gpt4 book ai didi

linux - 通过符号链接(symbolic link)启动应用程序时如何解析 rpath

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:48:31 28 4
gpt4 key购买 nike

我在 Linux 系统上使用 rpath 设置和符号链接(symbolic link)时遇到了这个问题。为了解释这个问题,我考虑了以下设置:

我有一个名为 foo 的应用程序,它依赖于 libbar.so。该应用程序驻留在 $ROOT/pkgs/foo-1.0/bin/ 中,并链接到 $ROOT/bin/。库 libbar.so 位于 $ROOT/lib/ 中。这给出了以下结构:

$ROOT/
bin/
foo --> $ROOT/pkgs/foo-1.0/bin/foo
lib/
libbar.so
pkgs/
foo-1.0/
bin/
foo

应用程序 foo 现在(以防止 LD_LIBRARY_PATH 设置)将 rpath 设置为 $ORIGIN/lib

现在的问题是 $ORIGIN/lib 是根据已解析的符号链接(symbolic link)解决的,而不是根据调用应用程序的路径($ROOT/bin). 如何改变?

一个可能的解决方案是切换到硬链接(hard link),这在这种情况下有效,但我不能确保链接不会指向跨文件系统边界,也不能确保文件系统支持硬链接(hard link)。

最佳答案

The problem now is $ORIGIN/lib is resolved with respect to the resolved symlink and not with respect to the path from where the application is called ($ROOT/bin). How can this be changed?

由于可执行文件不知道应用程序所在的符号链接(symbolic link)的路径,其中动态链接加载器 ld.so 解析运行时搜索路径,您的具体问题的答案是:不可能。
除此之外,nos 在他的评论中提到了可行的解决方案:您需要将 rpath 设置为 $ORIGIN/../../../lib …,或者制作 $ROOT/bin/foo 一个设置 LD_LIBRARY_PATH 的 shell 脚本。

关于linux - 通过符号链接(symbolic link)启动应用程序时如何解析 rpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34332571/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com