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++.
To compile the file with Insure++, perform the following command:
Once the compilation is completed, perform the following link command with Insure++:
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:
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.