Sample Header Ad - 728x90

Why might RUNPATH be ignored by the loader after system libraries are found?

1 vote
0 answers
228 views
I have an executable which is linked with several dynamic libraries (.so). These libraries are found in 2 different local folders. When linking the executable, the RUNPATH of the executable is correctly set to these two folders. When running the executable I'm getting loader errors telling me some libraries are not found. Inspecting with LD_DEBUG=libs ldd my_executable, shows that after having found one or more system libraries the loader is no more using the RUNPATH of the executable to search local libraries. At least this is my conclusion when inspected the output. What might be wrong? On my build, on my OS? I'm using Debian testing, but I have this problem also on Ubuntu 22.04. Here's a sketchup of my build:
/usr/bin/c++ \
-Wall \
-Wno-strict-aliasing \
-fdiagnostics-color=always \
main.cpp.o \
-o main \
-Wl,-rpath,/path/to/A:/path/to/B \
/path/to/A/lib1.so \
/path/to/A/lib2.so \
/path/to/B/lib3.so
When running LD_DEBUG=libs ldd main I'm getting something like this:
417465:     find library=lib1.so ; searching
417465:      search path=/path/to/A:/path/to/B     (RUNPATH from file ./main)
417465:       trying file=/path/to/A/lib1.so
417465:
417465:     find library=lib3.so ; searching
417465:      search path=/path/to/A:/path/to/B     (RUNPATH from file ./main)
417465:       trying file=/path/to/A/lib3.so
417465:       trying file=/path/to/B/lib3.so
417465:
417465:     find library=libmd.so.0 ; searching
417465:      search cache=/etc/ld.so.cache
417465:       trying file=/lib/x86_64-linux-gnu/libmd.so.0
417465:     
417465:     find library=libkrb5.so.3 ; searching
417465:      search cache=/etc/ld.so.cache
417465:       trying file=/lib/x86_64-linux-gnu/libkrb5.so.3
417465:     
417465:     find library=lib2.so ; searching
417465:      search cache=/etc/ld.so.cache
417465:      search path=/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/lib:/usr/lib              (system search path)
417465:       trying file=/lib/x86_64-linux-gnu/lib2.so
417465:       trying file=/usr/lib/x86_64-linux-gnu/lib2.so
417465:       trying file=/lib/lib2.so
417465:       trying file=/usr/lib/lib2.so
As we can see, RUNPATH is no more used after some library search steps.
Asked by Patrick B. (185 rep)
Jul 17, 2024, 04:56 PM