gcov最终链接失败 [英] gcov final link failed
问题描述
使用gcov支持编译项目时,我遇到以下错误
While compiling my project with gcov support I am facing the below error
以下是我在编译时拥有的标志信息
Following are flags information i have while compiling
编译器标志:
CXXFLAGS="-Wno-deprecated -g -ggdb -fprofile-arcs -ftest-coverage -fPIC"
链接器选项:
LINK_CMD="gcc -fprofile-arcs -fPIC"
以下是版本信息:
gcc版本:
gcc版本4.1.2 20080704(红帽4.1.2-44)
gcc version 4.1.2 20080704 (Red Hat 4.1.2-44)
gcov版本:
gcov(GCC)4.1.2 20080704(Red Hat 4.1.2-44)
gcov (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44)
错误:
DSO引用了/usr/lib/gcc/x86_64-redhat-linux/4.1.2/libgcov.a(_gcov.o)中的隐藏符号`__gcov_init' /usr/bin/ld:最终链接失败:输出中的不可代表部分 collect2:ld返回1个退出状态
hidden symbol `__gcov_init' in /usr/lib/gcc/x86_64-redhat-linux/4.1.2/libgcov.a(_gcov.o) is referenced by DSO /usr/bin/ld: final link failed: Nonrepresentable section on output collect2: ld returned 1 exit status
您能帮我摆脱这个问题吗?
Could you please help me to get away from this problem?
推荐答案
我已经可以使用以下步骤在自己的代码中解决此问题:
I have been able to solve this problem in my own code using these steps:
- 保持干净(删除我的所有.o和lib文件).
- 确保每个源文件都有正确的选项(-fprofile-arcs -ftest-coverage).
- 确保每个共享库的源文件都被编译为指定的-lgcov
- 确保我将可执行文件与-lgcov链接.