专家说LD_LIBRARY_PATH不好-有什么选择? [英] Gurus say that LD_LIBRARY_PATH is bad - what's the alternative?

查看:114
本文介绍了专家说LD_LIBRARY_PATH不好-有什么选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了一些有关使用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- path.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'

($ ORIGIN在与ld静态链接到共享库时,可能不起作用,请使用-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆