问题
Trying to compiler our code for code coverage using gcov. Getting following error:
hidden symbol `__gcov_merge_add' in /usr/lib/gcc/i686-redhat-linux/4.4.4/libgcov.a(_gcov_merge_add.o) is referenced by DSO /usr/bin/ld: final link failed: Nonrepresentable section on output collect2: ld returned 1 exit status
Following compiler options are newly added for gcov:
-O0 -fprofile-arcs -ftest-coverage -Xlinker -zmuldefs
and ld flags:
-fprofile-generate -fprofile-arcs
and linked with library -lgcov
Please suggest.
回答1:
We are able to enable the code coverage using simply --coverage -O0 compiler options and finally linking with -lgcov for RHEL 6.* version.
However same doesnt with debian where we had to use -O0 -fprofile-arcs -ftest-coverage -Xlinker -zmuldefs to make code coverage enabled binaries.
回答2:
Solution for this issue is
- Compile with
-fprofile-arcs -ftest-coverage - Link with
-fprofile-arcs -lgcov
I also got this same error when I was not using -fprofile-arcs while linking.
来源:https://stackoverflow.com/questions/16122599/gcc-ld-error-libgcov-a-gcov-merge-add-o-is-referenced-by-dso