gcov符号在哪里? [英] Where are the gcov symbols?

查看:766
本文介绍了gcov符号在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  gcc AllTests.o CuTestTest 

我试图用gcov编译一个简单的应用程序,并得到以下链接错误: .o CuTest.o -o TestTest
AllTests.o:在'全局构造函数键入0_RunAllTests':
/home/p7539c/cutest/AllTests.c:26:未定义的引用'__gcov_init'
AllTests.o :(。data + 0x44):未定义引用`__gcov_merge_add'
CuTestTest.o:在函数'keyed to 0_TestCuStringNew'的全局构造函数中:
/ home / p7539c / cutest / CuTestTest .c:30:对`__gcov_init'的未定义引用
CuTestTest.o :(。data + 0x64):对`__gcov_merge_add'的未定义引用
CuTest.o:在函数中`全局构造函数被键入0_CuStrAlloc':
/home/p7539c/cutest/CuTest.c:379:未定义引用`__gcov_init'
CuTest.o :(。data + 0x184):未定义引用`__gcov_merge_add'
collect2: ld返回1退出状态
make:*** [TestTest]错误1

我可以似乎找不到位置缺失的符号的重刑。运行gcc版本4.1.2的机器上存在gcov



有什么想法?感谢。



关于编辑:



使用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
  • 链接时仍然会出现奇怪的链接器错误。它们看起来像这样:
    $ b $ p $ lib $ .c(objfile.o):( .ctors + 0x0):'全局构造函数的未定义引用keying to long_name_of_file_and_function'




这意味着gconv与其中一个编译器 - 生成的构造函数(在我的情况下,复制构造函数)。检查错误消息中提到的函数,查看它复制哪些对象 - 构造,并查看是否有任何这些类没有复制构造函数。添加一个,错误将消失。



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


I'm trying to compile a simple app with gcov and getting the following link errors:

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

I can't seem to find the location of the missing symbols. gcov is present on the machine running gcc version 4.1.2

Any ideas? Thanks.

On Edit:

Everything seems to work fine when using gcov with an application that consists of one .c file. When I have multiple .c files (hence multiple .o files) I have the above problem.

The compile steps look like the following:

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

解决方案

I just spent an incredible amount of time debugging a very similar error. Here's what I learned:

  • You have to pass -fprofile-arcs -ftest-coverage when compiling.
  • You have to pass -fprofile-arcs when linking.
  • You can still get weird linker errors when linking. They'll look like this:

    libname.a(objfile.o):(.ctors+0x0): undefined reference to 'global constructors keyed to long_name_of_file_and_function'

This means that gconv's having problem with one of your compiler-generated constructors (in my case, a copy-constructor). Check the function mentioned in the error message, see what kinds of objects it copy-constructs, and see if any of those classes doesn't have a copy constructor. Add one, and the error will go away.

Edit: Whether or not you optimize can also affect this. Try turning on / switching off optimizations if you're having problems with it.

这篇关于gcov符号在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆