This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Linking against shared objects that reside at different paths on link-time versus runtime?
On 27 June 2011 19:24, Jonathan Wakely wrote:
>
> To ensure the library can be found at runtime, use LD_LIBRARY_PATH, or
> better use RPATH:
I forgot to add, you can investigate how the runtime linker finds the
dependencies using LD_DEBUG
$ LD_DEBUG=libs ldd ./a.out
...
7061: find library=libyyy.so [0]; searching
7061: search path=/tmp/tls/x86_64:/tmp/tls:/tmp/x86_64:/tmp
(RPATH from file ./a.out)
7061: trying file=/tmp/tls/x86_64/libyyy.so
7061: trying file=/tmp/tls/libyyy.so
7061: trying file=/tmp/x86_64/libyyy.so
7061: trying file=/tmp/libyyy.so
7061:
...
libyyy.so => /tmp/libyyy.so (0x00002b87148fd000)
$ rm libyyy.so
$ LD_DEBUG=libs LD_LIBRARY_PATH=/tmp/lib ldd ./a.out
...
7097: find library=libyyy.so [0]; searching
7097: search path=/tmp/tls/x86_64:/tmp/tls:/tmp/x86_64:/tmp
(RPATH from file ./a.out)
7097: trying file=/tmp/tls/x86_64/libyyy.so
7097: trying file=/tmp/tls/libyyy.so
7097: trying file=/tmp/x86_64/libyyy.so
7097: trying file=/tmp/libyyy.so
7097: search
path=/tmp/lib/tls/x86_64:/tmp/lib/tls:/tmp/lib/x86_64:/tmp/lib
(LD_LIBRARY_PATH)
7097: trying file=/tmp/lib/tls/x86_64/libyyy.so
7097: trying file=/tmp/lib/tls/libyyy.so
7097: trying file=/tmp/lib/x86_64/libyyy.so
7097: trying file=/tmp/lib/libyyy.so
7097: search cache=/etc/ld.so.cache
7097: search
path=/lib64/tls/x86_64:/lib64/tls:/lib64/x86_64:/lib64:/usr/lib64/tls/x86_64:/usr/lib64/tls:/usr/lib64/x86_64:/usr/lib64
(system search path)
7097: trying file=/lib64/tls/x86_64/libyyy.so
7097: trying file=/lib64/tls/libyyy.so
7097: trying file=/lib64/x86_64/libyyy.so
7097: trying file=/lib64/libyyy.so
7097: trying file=/usr/lib64/tls/x86_64/libyyy.so
7097: trying file=/usr/lib64/tls/libyyy.so
7097: trying file=/usr/lib64/x86_64/libyyy.so
7097: trying file=/usr/lib64/libyyy.so
...
libyyy.so => not found