Hi I have been looking around on topic about linking error - Error:: undefined reference to XXX,
My code compile on SUSE but not on REDHAT, appreciate if anyone can show me some light on this. I didn't find other post specifically match my situation (maybe I missed), there is a very close one (Linking with dynamic library with dependencies). I tried, however I still hit on rocks.
Background: I have a child.cpp which uses parent.cpp, so I have included parent.h in child.cpp
symbol (XXX) in parent is contained in libA.so
>> nm -C libA.so | egrep XXX
000000000013eb0 T NS::XXX(char const*, char const*, char const*)
There is another lib which uses parent, lets call it libB.so
>> nm -C libB.so | egrep XXX
000000000000000 U NS::XXX(char const*, char const*, char const*)
but libB.so has a link to libA.so
>> ldd libB.so | grep libA.so
libB.so => /export/data/NS/lib/libA.so (0x00007fbc0a9bf000)
When I link on SUSE, below compiles
g++ child.cpp -o child -I. -L. -lB
When I link on RHEL, it complains undefine XXX, so I have to do libA as well
g++ child.cpp -o child -I. -L. -lB -lA
I don't understand why there is a difference. I tried the options suggested in (Linking with dynamic library with dependencies). I still have to link libA when I compile.
-Wl,--unresolved-symbols=ignore-in-shared-libs
-Wl,--as-needed