0

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
Kelvin Lai
  • 79
  • 4
  • Show your code as an [MCVE], or at least improve your question to explain what really `XXX` and `libA.so` and `libB.so` are. Read also Drepper's [*How To Write Shared Libraries*](http://www.akkadia.org/drepper/dsohowto.pdf) – Basile Starynkevitch Sep 24 '18 at 07:30
  • libA and libB are only 3rd party libraries, they are transparent to me. What I know is the function API NS::XXX in parent.h – Kelvin Lai Sep 24 '18 at 15:19
  • Without additional details, you won't get any help. Consider complaining (or asking) the vendor of those 3rd party libraries. BTW, the backquotes in your commands are suspicious. Maybe you might link just `libB.so` or use different commands on SuSE and on RedHat. Maybe you should ask how to detect the distribution you are running on (and that makes a different question) – Basile Starynkevitch Sep 24 '18 at 22:40
  • What more details might help? Indeed I have no idea how replacing XXX with getName(), getCounter(), etc would help, I put XXX because the compiler complained everything refer defined in parent.h. I had 30+ errors. The most suspicious thing is that compiles on SUSE by just libB and I need libA + libB on RedHat. If XXX is undefined in libB but dynamic link to libA, what possible direction I should look into? – Kelvin Lai Sep 25 '18 at 10:03
  • If XXX is not defined in libB.so. What does "000000000000000 U NS::XXX(char const*, char const*, char const*)" mean? – Kelvin Lai Sep 25 '18 at 10:07
  • 1
    `libB.so` links `/export/data/NS/lib/libA.so`, but your command lines use `-L.`. Do `.` and `/export/data/NS/lib` refer to the same directory? – Maxim Egorushkin Sep 25 '18 at 11:26

0 Answers0