Solutions: Undefined reference errors occurr when linking in Insure++ symbols

 Insure++
 
Product Version7.4.3
 
Product PlatformsLinux 32; Linux 64
 
Solution SymptomsWhen linking instrumenting code with Insure++ on Ubuntu v12.04, we get the following messages or a similar message:

.../Insure++/lib/libinsure.so: undefined reference to `Insure::Thread::startFunction()'

.../Insure++/lib/libinsure.so: undefined reference to `Insure::NativeThread::newThread(Insure::Lock&)'

.../Insure++/lib/libinsure.so: undefined reference to `Insure::Mutex::newMutex(Insure::ThisThread*, Insure::LibraryCall&)'

.../Insure++/lib/libinsure.so: undefined reference to `Insure::Thread::thisThread()'

.../Insure++/lib/libinsure.so:: undefined reference to `Insure::Thread::fiberStartFunction()'

collect2: ld returned 1 exit status
 
Solution Details

Explanation + Solution

This behavior occurs because Ubuntu 12.04's linker, by default, attempts to optimize the symbols linked in.  This means the linker will throw away symbols it deems unnecessary, such as the Insure++ libraries.  However, these Insure++ libraries *are* required, as is proved by the linking error.  The solution is to add the linker option "-Wl,--no-as-needed" to prevent the linker from automatically optimizing the link line.





Example

In this example, let's assume the following.

  • OS : Ubuntu v12.04

  • Compiler : GCC v4.6.3

  • Insure++ v7.4.3



We would like to Instrument the following .c file with Insure++.

  • message_rec.c

To compile the file with Insure++, perform the following command:

  • $ insure gcc -g message_rec.c

Once the compilation is completed, perform the following link command with Insure++:

  • $ insure gcc -g -o message_rec message_rec.o

IF a similar output results from the above link command:

.../Insure++/lib/libinsure.so: undefined reference to `Insure::Thread::startFunction()'

.../Insure++/lib/libinsure.so: undefined reference to `Insure::NativeThread::newThread(Insure::Lock&)'

.../Insure++/lib/libinsure.so: undefined reference to `Insure::Mutex::newMutex(Insure::ThisThread*, Insure::LibraryCall&)'

.../Insure++/lib/libinsure.so: undefined reference to `Insure::Thread::thisThread()'

.../Insure++/lib/libinsure.so: undefined reference to `Insure::Thread::fiberStartFunction()'

collect2: ld returned 1 exit status



THEN the option "-Wl,--no-as-needed" needs to be added to the link command:

  • $ insure gcc -g -o message_rec message_rec.o -Wl,--no-as-needed

This will tell the linker to use all the symbols and do not throw any of the symbols away.  The link should no longer produce the same error.

转载于:https://www.cnblogs.com/kwang-cai/p/5429968.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值