Ricardo
Ricardo

Reputation: 255

Change search path for shared library to rpath provided in Makefile

I use a C++-shared-library libA.so that requires libB.so.1.0, while there is libB.so.2.0 installed on my system.

I'm not able to change this or to add any files to /usr/lib/ or /lib/.

I have transferred libB.so.1.0 to my local lib-folder and linked the application against it using rpath. However, this path is not used to find libB.so.1.0 for libA.so(but the rpath is used for other shared-libraries that are linked directly). Chrpath can only be used to change an existing rpath, but this library uses the system search path. So I believe this not to be an option.

The question is: Is there a way to propagate my rpath set in my Makefile to the indirectly included library libB.so.1.0 and if not, what other options do I have, preferably without setting LD_LIBRARY_PATH manually?

The ldd- Ouput (for libA.so) looks like this:

 11118: find library=libboost_system.so.1.58.0 [0]; searching
11118:   search cache=/etc/ld.so.cache
11118:   search path=/lib/x86_64-linux-gnu/tls/haswell/x86_64:/lib/x86_64-
linux-gnu/tls/haswell:/lib/x86_64-linux-gnu/tls/x86_64:/lib/x86_64-linux-
gnu/tls:/lib/x86_64-linux-gnu/haswell/x86_64:/lib/x86_64-linux-gnu/haswell:
/lib/x86_64-linux-gnu/x86_64:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-    
gnu/tls/haswell/x86_64:/usr/lib/x86_64-linux-gnu/tls/haswell:/usr/lib/x86_64-
linux-gnu/tls/x86_64:/usr/lib/x86_64-linux-gnu/tls:/usr/lib/x86_64-linux-
gnu/haswell/x86_64:/usr/lib/x86_64-linux-gnu/haswell:/usr/lib/x86_64-linux-
gnu/x86_64:/usr/lib/x86_64-linux-gnu:/lib/tls/haswell/x86_64:/lib/tls/haswell:
/lib/tls/x86_64:/lib/tls:/lib/haswell/x86_64:/lib/haswell:/lib/x86_64:
/lib:/usr/lib/tls/haswell/x86_64:/usr/lib/tls/haswell:/usr/lib/tls/x86_64:
/usr/lib/tls:/usr/lib/haswell/x86_64:/usr/lib/haswell:/usr/lib/x86_64:
/usr/lib        (system search path)
 11118:   trying file=/lib/x86_64-linux-gnu/tls/haswell/x86_64/libboost_system.so.1.58.0
 11118:   trying file=/lib/x86_64-linux-gnu/tls/haswell/libboost_system.so.1.58.0
 11118:   trying file=/lib/x86_64-linux-gnu/tls/x86_64/libboost_system.so.1.58.0
 11118:   trying file=/lib/x86_64-linux-gnu/tls/libboost_system.so.1.58.0
 11118:   trying file=/lib/x86_64-linux-gnu/haswell/x86_64/libboost_system.so.1.58.0
 11118:   trying file=/lib/x86_64-linux-gnu/haswell/libboost_system.so.1.58.0
 11118:   trying file=/lib/x86_64-linux-gnu/x86_64/libboost_system.so.1.58.0
 11118:   trying file=/lib/x86_64-linux-gnu/libboost_system.so.1.58.0
 11118:   trying file=/usr/lib/x86_64-linux-gnu/tls/haswell/x86_64/libboost_system.so.1.58.0
 11118:   trying file=/usr/lib/x86_64-linux-gnu/tls/haswell/libboost_system.so.1.58.0
 11118:   trying file=/usr/lib/x86_64-linux-gnu/tls/x86_64/libboost_system.so.1.58.0
 11118:   trying file=/usr/lib/x86_64-linux-gnu/tls/libboost_system.so.1.58.0
 11118:   trying file=/usr/lib/x86_64-linux-gnu/haswell/x86_64/libboost_system.so.1.58.0
 11118:   trying file=/usr/lib/x86_64-linux-gnu/haswell/libboost_system.so.1.58.0
 11118:   trying file=/usr/lib/x86_64-linux-gnu/x86_64/libboost_system.so.1.58.0
 11118:   trying file=/usr/lib/x86_64-linux-gnu/libboost_system.so.1.58.0
 11118:   trying file=/lib/tls/haswell/x86_64/libboost_system.so.1.58.0
 11118:   trying file=/lib/tls/haswell/libboost_system.so.1.58.0
 11118:   trying file=/lib/tls/x86_64/libboost_system.so.1.58.0
 11118:   trying file=/lib/tls/libboost_system.so.1.58.0
 11118:   trying file=/lib/haswell/x86_64/libboost_system.so.1.58.0
 11118:   trying file=/lib/haswell/libboost_system.so.1.58.0
 11118:   trying file=/lib/x86_64/libboost_system.so.1.58.0
 11118:   trying file=/lib/libboost_system.so.1.58.0
 11118:   trying file=/usr/lib/tls/haswell/x86_64/libboost_system.so.1.58.0
 11118:   trying file=/usr/lib/tls/haswell/libboost_system.so.1.58.0
 11118:   trying file=/usr/lib/tls/x86_64/libboost_system.so.1.58.0
 11118:   trying file=/usr/lib/tls/libboost_system.so.1.58.0
 11118:   trying file=/usr/lib/haswell/x86_64/libboost_system.so.1.58.0
 11118:   trying file=/usr/lib/haswell/libboost_system.so.1.58.0
 11118:   trying file=/usr/lib/x86_64/libboost_system.so.1.58.0
 11118:   trying file=/usr/lib/libboost_system.so.1.58.0

Upvotes: 2

Views: 721

Answers (1)

Employed Russian
Employed Russian

Reputation: 213375

I have transferred libB.so.1.0 to my local lib-folder and linked the application against it using rpath. However, this path is not used to find libB.so.1.0 for libA.so(but the rpath is used for other shared-libraries that are linked directly).

That is the expected behavior when the application has RUNPATH (which is the newer default when -rpath is specified at link time).

You want the "recursive" behavior of RPATH instead. Documentation explaining the difference.

Step 1: confirm that your app is indeed using RUNPATH:

readelf -d a.out | egrep 'RPATH|RUNPATH'

Step 2: use -rpath=... -Wl,--disable-new-dtags to link your application, and confirm that RPATH is now being used.

Step 3: confirm that libB.so.1.0 is now found.

Enjoy :-)

Upvotes: 2

Related Questions