我正在尝试使用gcov编译一个简单的应用程序,但是出现了以下链接错误:
gcc AllTests.o CuTestTest.o CuTest.o -o TestTest
AllTests.o: In function `global constructors keyed to 0_RunAllTests':
/home/p7539c/cutest/AllTests.c:26: undefined reference to `__gcov_init'
AllTests.o:(.data+0x44): undefined reference to `__gcov_merge_add'
CuTestTest.o: In function `global constructors keyed to 0_TestCuStringNew':
/home/p7539c/cutest/CuTestTest.c:30: undefined reference to `__gcov_init'
CuTestTest.o:(.data+0x64): undefined reference to `__gcov_merge_add'
CuTest.o: In function `global constructors keyed to 0_CuStrAlloc':
/home/p7539c/cutest/CuTest.c:379: undefined reference to `__gcov_init'
CuTest.o:(.data+0x184): undefined reference to `__gcov_merge_add'
collect2: ld returned 1 exit status
make: *** [TestTest] Error 1
我似乎找不到缺失符号的位置。在运行gcc版本4.1.2的机器上,gcov存在。
有什么想法吗?谢谢。
编辑后:
使用只包含一个.c文件的应用程序时,gcov似乎一切正常。当我有多个.c文件(因此有多个.o文件)时,我遇到了上述问题。
编译步骤如下:
cc -fprofile-arcs -ftest-coverage -g -c -o AllTests.o AllTests.c
cc -fprofile-arcs -ftest-coverage -g -c -o CuTestTest.o CuTestTest.c
cc -fprofile-arcs -ftest-coverage -g -c -o CuTest.o CuTest.c