Reputation: 203
I have been working on compiling an executable which has 2 shared object dependencies. I have stored both .so files in the same directory as the executable, so I set the INSTALL_RPATH property of my executable to "$ORIGIN" and it succeeds at finding one library but not the other.
set_property(TARGET testExecutable PROPERTY INSTALL_RPATH "$ORIGIN")
I used LD_DEBUG to help trouble shoot this problem. The first dependency is located as expected:
70397: find library=lib1.so [0]; searching
70397: search path=/home/me/software/myproject/build/myproject-install/bin/tls/x86_64/x86_64:/home/me/software/myproject/build/myproject-install/bin/tls/x86_64:/home/me/software/myproject/build/myproject-install/bin/tls/x86_64:/home/me/software/myproject/build/myproject-install/bin/tls:/home/me/software/myproject/build/myproject-install/bin/x86_64/x86_64:/home/me/software/myproject/build/myproject-install/bin/x86_64:/home/me/software/myproject/build/myproject-install/bin/x86_64:/home/me/software/myproject/build/myproject-install/bin (RUNPATH from file ./myproject-install/bin/testExecutable)
70397: trying file=/home/me/software/myproject/build/myproject-install/bin/tls/x86_64/x86_64/lib1.so
70397: trying file=/home/me/software/myproject/build/myproject-install/bin/tls/x86_64/lib1.so
70397: trying file=/home/me/software/myproject/build/myproject-install/bin/tls/x86_64/lib1.so
70397: trying file=/home/me/software/myproject/build/myproject-install/bin/tls/lib1.so
70397: trying file=/home/me/software/myproject/build/myproject-install/bin/x86_64/x86_64/lib1.so
70397: trying file=/home/me/software/myproject/build/myproject-install/bin/x86_64/lib1.so
70397: trying file=/home/me/software/myproject/build/myproject-install/bin/x86_64/lib1.so
70397: trying file=/home/me/software/myproject/build/myproject-install/bin/lib1.so
But for the second dependency, the specified RPATH is not even searched.
70397: find library=lib2.so [0]; searching
70397: search cache=/etc/ld.so.cache
70397: search path=/lib/x86_64-linux-gnu/tls/x86_64/x86_64:/lib/x86_64-linux-gnu/tls/x86_64:/lib/x86_64-linux-gnu/tls/x86_64:/lib/x86_64-linux-gnu/tls:/lib/x86_64-linux-gnu/x86_64/x86_64:/lib/x86_64-linux-gnu/x86_64:/lib/x86_64-linux-gnu/x86_64:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu/tls/x86_64/x86_64:/usr/lib/x86_64-linux-gnu/tls/x86_64:/usr/lib/x86_64-linux-gnu/tls/x86_64:/usr/lib/x86_64-linux-gnu/tls:/usr/lib/x86_64-linux-gnu/x86_64/x86_64:/usr/lib/x86_64-linux-gnu/x86_64:/usr/lib/x86_64-linux-gnu/x86_64:/usr/lib/x86_64-linux-gnu:/lib/tls/x86_64/x86_64:/lib/tls/x86_64:/lib/tls/x86_64:/lib/tls:/lib/x86_64/x86_64:/lib/x86_64:/lib/x86_64:/lib:/usr/lib/tls/x86_64/x86_64:/usr/lib/tls/x86_64:/usr/lib/tls/x86_64:/usr/lib/tls:/usr/lib/x86_64/x86_64:/usr/lib/x86_64:/usr/lib/x86_64:/usr/lib (system search path)
70397: trying file=/lib/x86_64-linux-gnu/tls/x86_64/x86_64/lib2.so
70397: trying file=/lib/x86_64-linux-gnu/tls/x86_64/lib2.so
70397: trying file=/lib/x86_64-linux-gnu/tls/x86_64/lib2.so
70397: trying file=/lib/x86_64-linux-gnu/tls/lib2.so
70397: trying file=/lib/x86_64-linux-gnu/x86_64/x86_64/lib2.so
70397: trying file=/lib/x86_64-linux-gnu/x86_64/lib2.so
70397: trying file=/lib/x86_64-linux-gnu/x86_64/lib2.so
70397: trying file=/lib/x86_64-linux-gnu/lib2.so
70397: trying file=/usr/lib/x86_64-linux-gnu/tls/x86_64/x86_64/lib2.so
70397: trying file=/usr/lib/x86_64-linux-gnu/tls/x86_64/lib2.so
70397: trying file=/usr/lib/x86_64-linux-gnu/tls/x86_64/lib2.so
70397: trying file=/usr/lib/x86_64-linux-gnu/tls/lib2.so
70397: trying file=/usr/lib/x86_64-linux-gnu/x86_64/x86_64/lib2.so
70397: trying file=/usr/lib/x86_64-linux-gnu/x86_64/lib2.so
70397: trying file=/usr/lib/x86_64-linux-gnu/x86_64/lib2.so
70397: trying file=/usr/lib/x86_64-linux-gnu/lib2.so
70397: trying file=/lib/tls/x86_64/x86_64/lib2.so
70397: trying file=/lib/tls/x86_64/lib2.so
70397: trying file=/lib/tls/x86_64/lib2.so
70397: trying file=/lib/tls/lib2.so
70397: trying file=/lib/x86_64/x86_64/lib2.so
70397: trying file=/lib/x86_64/lib2.so
70397: trying file=/lib/x86_64/lib2.so
70397: trying file=/lib/lib2.so
70397: trying file=/usr/lib/tls/x86_64/x86_64/lib2.so
70397: trying file=/usr/lib/tls/x86_64/lib2.so
70397: trying file=/usr/lib/tls/x86_64/lib2.so
70397: trying file=/usr/lib/tls/lib2.so
70397: trying file=/usr/lib/x86_64/x86_64/lib2.so
70397: trying file=/usr/lib/x86_64/lib2.so
70397: trying file=/usr/lib/x86_64/lib2.so
70397: trying file=/usr/lib/lib2.so
I think the key is that the search for lib1 states (RUNPATH from file ./myproject-install/bin/testExecutable)
whereas the search for lib2 states (system search path)
I don't understand why the RPATH differs for the 2 libraries, when the RPATH property was set for the TARGET, which does not change.
The failing library comes from an ExternalProject which has been linked. The other is created within this cmake script.
Upvotes: 2
Views: 785
Reputation: 203
The solution was to set the RPATH for both lib1.so and for lib2.so. I think the issue may have actually been that lib1 also depends on lib2, so the search was not initiated by testExecutable, rather by lib1, a dependency of testExecutable.
Upvotes: 1