Problem
When we introduced Gocv to build my project for code coverage, I encountered the following error message:
error 1
g++ -m64 -z muldefs -L/lib64 -L/usr/lib64 -lglib-2.0 -m64 -DUV_64PORT -DU2_64_BUILD -fPIC -g DU_starter.o |
error 2
It may also be such an error
/home/p7539c/cutest/CuTest.c:379: undefined reference to `__gcov_init' |
Positioning problem
Let’s take the error 1.
From the error message, I noticed -lundata -lutcallc_nfasvr
are all the linked libraries (-llibrary)
I checked libraries undata
and utcallc_nfasvr
one by one, and found it displayed U __gcov_init
and U
means undefined symbols.
Use the
find
command to search the library and thenm
command to list symbols in the library.
-sh-4.2$ find -name *utcallc_nfasvr* |
How to fix
In my case, I just added the following code LIB_1_LIBS := -lgcov
to allow the utcallc_nfasvr
library to call gcov.
LIB_1 := utcallc_nfasvr |
Rebuild, the error is gone, then checked library, it displayed t __gcov_init
this time, it means symbol value exists not hidden.
-sh-4.2$ nm ./bin/libutcallc_nfasvr.so | grep __gcov_init |
Or in your case may build a shared library like so, similarly, just add the compile parameter -lgcov
g++ -shared -o libMyLib.so src_a.o src_b.o src_c.o -lgcov |
Summary
I have encountered the following problems many times
undefined reference to `__gcov_init' |
Each time I can fix it by adding -glcov
then recompile. the error has gone after rebuild. (you use the nm
command to double-check whether the symbol has been added successfully.)
Hopes it can help you.