zoukankan      html  css  js  c++  java
  • Solutions: Undefined reference errors occurr when linking in Insure++ symbols

      Insure++
     
    Product Version 7.4.3
     
    Product Platforms Linux 32; Linux 64
     
    Solution Symptoms When 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.

  • 相关阅读:
    再谈每周工作不要超过 40 小时
    前苹果雇员潜入总部 只为完成自己的项目
    C语言解析pcap文件得到HTTP信息实例(原创,附源码)
    Android 2.1 源码结构分析
    linux 获取当前日期与时间
    谷歌史上十大优秀产品榜:Android傲娇上位
    在eclipse中查看android SDK的源代码
    网络开发必备的HTTP协议知识
    Linux TCP/IP协议栈源码阅读笔记
    浅析UPnP协议
  • 原文地址:https://www.cnblogs.com/kwang-cai/p/5429968.html
Copyright © 2011-2022 走看看