Search code examples
c++g++ldgenicam

Linker error: undefined reference to xxx after including .so lib


Undefined reference event with -lmylib and -LmyPath explicitely in my command.

I am trying to compile a test program using genicam API. This API provides shared libraries for linux with all the needed definitions. My command is as follows:

g++ -L/lib -lrt -ldl -Wl,-E -pthread -o mytest <some .o files>  
-lFirmwareUpdate_gcc49_v3_1_IDS -llog4cpp_gcc49_v3_1_IDS 
-lGCBase_gcc49_v3_1_IDS -lLog_gcc49_v3_1_IDS -lMathParser_gcc49_v3_1_IDS 
-lNodeMapData_gcc49_v3_1_IDS -lXmlParser_gcc49_v3_1_IDS 
-lGenApi_gcc49_v3_1_IDS

The program compiles but all the references to definitions supposed to be in the .so files are undefined, according to the linker, for example:

/usr/bin/ld: <my.o>: in function <myObject>::setTriggerMode(char const*):
my.cpp:271: undefined reference to GenICam_3_1::gcstring::gcstring(char const*)'

I tried to have a look inside of the libs and, to keep the same example:

nm -D /lib/libGCBase_gcc49_v3_1_IDS.so | grep -i gcstring
000000000000c400 T _ZN15GenICam_3_1_IDS8gcstringC1Emc

This line is not the only output line but it really seems that gcstring is fully defined in there...

So, I tried to know if ld was making fun of me or not and run my compilation command again with strace (-f). ld is really opening the good .so files and finds it!

Thank you for your help, I have no clue what happens.


Solution

  • Found the issue! It was because of IDS (cam vendor) that provides api's modified shared objects but with modified entry names (same names with IDS in it)...

    Got the real libs from github and it works!