LD_LIBRARY_PATH 优先级
我刚刚偶然发现了一些奇怪的行为:在启动应用程序之前,我已将 LD_LIBRARY_PATH 设置为某个包含所有所需库的本地 lib 目录。启动后,我有部分(大部分)库是从 LD_LIBRARY_PATH 加载的,但有一些是从标准 /usr/lib 加载的(例如 /usr/lib/libQtNetwork.so.4、/usr/lib/libSM.so)。 6).所有这些库都包含在 LD_LIBRARY_PATH 中列出的目录中。谁能解释一下为什么我会有这样的行为? 我对 Linux 世界不是很熟悉,但是这篇文章说我的方法应该
有效如果我将 /usr/libs 重命名为其他名称,我的应用程序将使用我的库位置中使用的所有库运行
提前致谢!
I've just stumbled on some weird behavior: before I launch my application I've set the LD_LIBRARY_PATH to some local lib directory which contains all needed libs. After launch I have part(the most part) libs are loaded from the LD_LIBRARY_PATH but a few are loaded from the standard /usr/lib(e.g /usr/lib/libQtNetwork.so.4, /usr/lib/libSM.so.6). All those libs are contained in the directory which is listed in the LD_LIBRARY_PATH. Could anyone explain why do I have such behavior?
I'm not very familiar with a Linux world but this article says that my approach should work
P.S. If I rename /usr/libs to something other I'll have my application running with all libs used from my libs location
Thank in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了答案,答案是RPATH。所有 Qt 库都是使用 RPATH=$QT_INSTALL_DIR 构建的,因此如果您想在 Linux 中创建“捆绑包”,则应删除 RPATH。 RPATH 可以通过调用 chrpath 命令删除。感谢大家的帮助!
I've found the answer and the answer is RPATH. All Qt libraries are built with RPATH=$QT_INSTALL_DIR so the RPATH should be removed if you want to create "bundle" in Linux. RPATH can be removed by invoking chrpath command. Thanks all for help!
好的,看来您正在使用 Qt,但同样的原则适用,并且不是 Qt 特定的。
首先要查看的是您的 PATH 环境变量,然后是 QTDIR,然后是 LD_LIBRARY_PATH。
通常你不需要“玩弄”LD_LIBRARY_PATH。如果你的路径是正确的,那么你应该没问题。
附带说明(您可能知道):要查看使用的库,您可以使用 ldd 命令。例如:
假设您的 QTDIR 环境变量已设置。如果你有 QT,如果 linux 发行版安装了 qmake 将在路径中。如果您进行了自定义安装或编译,则需要设置路径。
祝你好运。
Ok, seems you are using Qt, but the same principles applies and is not Qt specific.
The first thing to look at is your PATH environment variable, then QTDIR, then LD_LIBRARY_PATH.
Normally you do not need to "play" with LD_LIBRARY_PATH. If your PATH is correct then you should be fine.
As a side note (you probably know): To see the libraries used you can use the the ldd command. For example:
Assuming your QTDIR env variable is set. If you have QT if the linux distribution installed qmake will be in the path. If you did a custom install or compile you would need to set your path.
Good luck.