I am porting a large C++ library (libcoro.so) and example application (coro-example.cpp) from Windows to RedHat Linux 7.4. I have very little development experience on Linux, so this is probably a ‘newbie’ question. I have libcoro and the example app compiling, linking, and running on my RHEL 7.4 VM. However, the gcc linker fails to link the app on the customer’s RHEL 7.4 machine when he tries to link coro-example.o to libcoro.so. The error message is:
/usr/bin/ld: warning: libusb-0.1.so.4, needed by ./bin/libcoro.so not found (try using -rpath or -rpath-link)
libcoro.so: undefined reference to ‘usb_open’
libcoro.so: undefined reference to ‘usb_release_interface’
…etc…
Running ‘ldd coro.so’ on my machine displays:
libusb-0.1.so.4 => /lib64/libusb-0.1.so.4 (0x00007f71115db000)
…etc…
And on the customer’s machine:
libusb-0.1.so.4 => not found
[many other libs] => not found
…etc…
Indeed, these libraries are in my /lib64 folder, but are not in the customer’s. I’m not sure how they got installed on my machine. I have access to the missing libraries and can deliver them with my libcoro.so library. I really want my app to be self-contained and run on any RHEL 7.x machine. My question is:
What is the best way to identify which libraries are not part of the RHEL 7.x installation and have the linker fail on my machine if I’m not delivering a local copy? I tried linking with -nodefaultlibs, but the link fails on functions like printf() and I haven’t found a way to locate these standard libraries. They don’t appear to be in /lib64.
Is there a way to exclude /lib64 from the default library search?
Advertisement
Answer
There is a linker switch -Wl,--no-undefined
which seems to do what I want. It fails to link and generates an error is the library is isn’t explicitly named. Also, the command ldd libcoro.so
lists all dependencies and where they are being resolved. I also found this this article very helpful.