I want to remove some of the paths the linker uses to find .so libraries for testing purposes.
I have found a way to add library paths:
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/path/to/library"
Are there a variable similar to LD_LIBRARY_PATH
that I can use to remove library paths such as /usr/local/lib
or /usr/lib
that are not in LD_LIBRARY_PATH
but picked up by the linker? I.e. how can I ignore paths that are given in /etc/ld.so.conf.d/ ?
The reason for this is that I am busy creating a program that, for a given executable, it recursively finds library dependencies. I want to see if I can make a program more portable by finding all its dependencies, copying those dependencies into a local directory, and make a local-run bash script to setup LD_LIBRARY_PATH and then run the executable. I want to test if this local-run-executable works after previously important library search paths are removed.
Best Answer
You would be interested in removing library paths if a given shared library has embedded paths via the rpath feature. Those are added at the time the library is created by the linker.
You can remove (or alter) those paths using
chrpath
, e.g.,Removing pathnames from the
LD_LIBRARY_PATH
variable also is a possible area of interest; you can do that by string substitution and re-exporting the variable. However, the question does not seem to be concerned with that. There is no variable which acts to cancel outLD_LIBRARY_PATH
.For seeing library dependencies, the mention of
/etc/ld.so.conf.d/
makes it sound as if the platform is only Linux. You can useldd
to list dependencies. Aside from OSX, all of the BSDs also supportldd
. Here is one of the scripts which I use for this purpose:But (addressing a comment), there is no portable mechanism for telling the loader to ignore an existing path. The GNU ld documentation gives a summary of what is sought, and the order in the description of the
-rpath
option. These items conclude the list:Further reading