大师们说 LD_LIBRARY_PATH 不好 - 有什么选择? [英] Gurus say that LD_LIBRARY_PATH is bad - what's the alternative?
问题描述
我阅读了一些关于使用 LD_LIBRARY_PATH 的问题的文章,甚至作为包装脚本的一部分:
I read some articles about problems in using the LD_LIBRARY_PATH, even as a part of a wrapper script:
http://linuxmafia.com/faq/Admin/ld-lib-路径.html
http://blogs.oracle.com/ali/entry/avoiding_ld_library_path_the
在这种情况下 - 推荐的替代方案是什么?
In this case - what are the recommended alternatives?
谢谢.
推荐答案
你可以试试添加:
-Wl,-rpath,path/to/lib
链接器选项.这将使您不必担心 LD_LIBRARY_PATH
环境变量,并且您可以在 编译时 决定指向特定的库.
to the linker options. This will save you the need to worry about the LD_LIBRARY_PATH
environment variable, and you can decide at compile time to point to a specific library.
相对于二进制的路径,可以使用$ORIGIN,例如
For a path relative to the binary, you can use $ORIGIN, eg
-Wl,-rpath,'$ORIGIN/../lib'
(使用 ld 静态链接到共享库时,$ORIGIN 可能不起作用,请使用 -Wl,--allow-shlib-undefined 来解决此问题)
($ORIGIN may not work when statically linking to shared libraries with ld, use -Wl,--allow-shlib-undefined to fix this)
这篇关于大师们说 LD_LIBRARY_PATH 不好 - 有什么选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!