Qwe*_*tie 4 rpath shared-libraries ld
在CentOS 7.2,我已经建立了与G ++ 4.8.5应用程序,因为它不能找到一个库,无法运行确实存在的runpath。我很确定它在两周前有效。什么可能导致这种情况?
$ ./app
./app: error while loading shared libraries: libhdf5.so.9: cannot open shared object file: No such file or directory
$ ldd ./app | grep libhdf5
libhdf5.so.9 => not found
$ readelf app -d | grep path
0x000000000000001d (RUNPATH) Library runpath: [/opt/ProductName/lib:/opt/ProductName/lib/private]
$ ll /opt/ProductName/lib/libhdf5.so*
lrwxrwxrwx. 1 fotechd fotechd 16 Oct 26 14:38 /opt/ProductName/lib/libhdf5.so -> libhdf5.so.9.0.0
lrwxrwxrwx. 1 fotechd fotechd 16 Oct 26 14:38 /opt/ProductName/lib/libhdf5.so.9 -> libhdf5.so.9.0.0
-rwxr-xr-x. 1 fotechd fotechd 3316074 Oct 26 14:35 /opt/ProductName/lib/libhdf5.so.9.0.0
Run Code Online (Sandbox Code Playgroud)
设置LD_LIBRARY_PATH暂时修复它:
$ LD_LIBRARY_PATH=/opt/ProductName/lib ./app
...
OK
Run Code Online (Sandbox Code Playgroud)
我已经能够在我这边解决这个问题。对我来说,这是因为未找到的库是一个间接库,runpath实际上并没有解决间接依赖关系。我使用 usingrpath而不是runpath通过将附加-Wl,--disable-new-dtags链接器选项传递给编译器来修复它。
这里有一个很好的详细解释:How to set RPATH and RUNPATH with GCC/LD?