Ubuntu中的临时库搜索路径(Temporary Library Search Path in Ubuntu)

我有我的程序动态链接的同一个库的多个版本。 有时候我想改变使用的版本。

我一直在阅读新版本的Ubuntu出于安全原因不再支持LD_LIBRARY_PATH 。 我可以添加路径到/etc/ld.so.conf并运行ldconfig但我不会总是拥有系统的root权限。

任何人都知道如何更改库搜索路径,普通用户可以做出什么? 假设经常发生更新配置文件是最后的手段。

编辑:这里是我如何测试,我期望看到的等等:我在程序上运行ldd并查看libfoo.so => /some/path/to/lib/libfoo.so 。 我将/path/to/different/version/lib (其中包含一个名为libfoo.so的文件) LD_LIBRARY_PATH然后重新运行ldd 。 当我希望看到libfoo.so => /path/to/different/version/lib/libfoo.so时,libfoo.so的路径与之前的路径相同。

谢谢,

安德鲁

I've got multiple version of the same library to which my program dynamically links. Sometimes I'd like to change the version that gets used.

I've been reading that new versions of Ubuntu no longer support LD_LIBRARY_PATH for security reasons. I could add the path to /etc/ld.so.conf and run ldconfig but I won't always have root privileges on the system.

Anyone know how to make a change to the library search path, that a plain user can make? Assume that it happens often enough that updating config files is a last resort.

Edit: Here is how I'm testing, what I expect to see and so on: I run ldd on a program and see libfoo.so => /some/path/to/lib/libfoo.so. I prepend /path/to/different/version/lib (which contains a file named libfoo.so) to LD_LIBRARY_PATH and rerun ldd. The path for libfoo.so is the same as before when I'd expect to see libfoo.so => /path/to/different/version/lib/libfoo.so.

Thanks,

Andrew

最满意答案

您可以使用patchelf更改任何可执行文件的RPATH (库搜索路径)。 这是一个很酷的工具,不需要特殊的权限来运行。 要将程序设置为首先搜索/opt/my-libs/lib然后/foo/lib ,只需执行以下操作:

% patchelf --set-rpath /opt/my-libs/lib:/foo/lib program

You can use patchelf to change the RPATH (library search path) of any executable. It's a cool utility, and does not require special privileges to run. To set a program to first search /opt/my-libs/lib then /foo/lib, just do this:

% patchelf --set-rpath /opt/my-libs/lib:/foo/lib program

更多推荐