我一直在编译具有2个共享库依赖项的可执行文件。我将这两个.so文件都与可执行文件存储在同一目录中,因此我将我的可执行文件的INSTALL_RPATH属性设置为“ $ ORIGIN”,它成功地找到了一个库,但没有找到另一个库。
set_property(TARGET testExecutable PROPERTY INSTALL_RPATH "$ORIGIN")
我使用LD_DEBUG帮助解决此问题。第一个依赖项位于预期位置:
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
但是对于第二个依赖项,甚至不搜索指定的RPATH。
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
我认为关键是搜索lib1的状态为(RUNPATH from file ./myproject-install/bin/testExecutable)
而搜索lib2的状态为(system search path)
当为TARGET设置RPATH属性时,我不明白为什么两个库的RPATH会有所不同,而这不会改变。
失败的库来自已链接的ExternalProject。另一个在此cmake脚本中创建。
答案 0 :(得分:0)
解决方案是同时为lib1.so和lib2.so设置RPATH。我认为问题可能实际上是lib1也依赖于lib2,所以搜索不是由testExecutable发起的,而是由lib1(testExecutable的依赖项)发起的。