通过符号链接启动应用程序时如何解析 rpath
How is the rpath resolved when the application is started via a symlink
我在 Linux 系统上使用 rpath
设置和符号链接时遇到了这个问题。为了解释这个问题,我考虑了以下设置:
我有一个名为 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
是针对已解析的符号链接解决的,而不是针对调用应用程序的路径 ($ROOT/bin
) 解决的。 如何更改?
一个可能的解决方案是切换到硬链接,这在这种情况下有效,但我不能确保链接不会指向跨文件系统边界,也不能确保文件系统支持硬链接。
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?
由于可执行文件不知道应用程序所在的符号链接的路径,其中动态链接加载程序 ld.so
解析 运行 时间搜索路径,你具体问题的答案是:不行。
除此之外,nos 在他的评论中提到了可行的解决方案:you'd need to set the rpath to $ORIGIN/../../../lib …, or make $ROOT/bin/foo
a shell 设置 LD_LIBRARY_PATH
.
的脚本
我在 Linux 系统上使用 rpath
设置和符号链接时遇到了这个问题。为了解释这个问题,我考虑了以下设置:
我有一个名为 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
是针对已解析的符号链接解决的,而不是针对调用应用程序的路径 ($ROOT/bin
) 解决的。 如何更改?
一个可能的解决方案是切换到硬链接,这在这种情况下有效,但我不能确保链接不会指向跨文件系统边界,也不能确保文件系统支持硬链接。
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?
由于可执行文件不知道应用程序所在的符号链接的路径,其中动态链接加载程序 ld.so
解析 运行 时间搜索路径,你具体问题的答案是:不行。
除此之外,nos 在他的评论中提到了可行的解决方案:you'd need to set the rpath to $ORIGIN/../../../lib …, or make $ROOT/bin/foo
a shell 设置 LD_LIBRARY_PATH
.