Temporary Library Search Path in Ubuntu
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
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
精彩评论