gpt4 book ai didi

gcc - gcov 符号在哪里?

转载 作者:行者123 更新时间:2023-12-03 05:43:54 25 4
gpt4 key购买 nike

我尝试使用 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

我似乎找不到丢失符号的位置。 gcov 存在于运行 gcc 版本 4.1.2 的计算机上

有什么想法吗?谢谢。

编辑时:

将 gcov 与包含一个 .c 文件的应用程序一起使用时,一切似乎都工作正常。当我有多个 .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

最佳答案

我刚刚花了令人难以置信的时间来调试一个非常相似的错误。这是我学到的:

  • 编译时必须传递-fprofile-arcs -ftest-coverage
  • 链接时必须传递-fprofile-arcs
  • 链接时您仍然会遇到奇怪的链接器错误。它们看起来像这样:

    libname.a(objfile.o):(.ctors+0x0):对“以 long_name_of_file_and_function 为键的全局构造函数”的 undefined reference

这意味着 gconv 的编译器生成的构造函数之一(在我的例子中是复制构造函数)存在问题。检查错误消息中提到的函数,查看它复制构造的对象类型,并查看这些类中是否有任何一个没有复制构造函数。添加一个,错误就会消失。

编辑:是否优化也会影响这一点。如果您遇到问题,请尝试打开/关闭优化。

关于gcc - gcov 符号在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/566472/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com