What is the order that Linux's dynamic linker searches paths in?
26
votes
1
answer
47584
views
This is not a duplicate because this is dealing with a peculiarity I noticed when I use
/etc/ld.so.conf
.
To get the paths that the dynamic linker searches in for libraries, I run the command ldconfig -v | grep -v "^"$'\t' | sed "s/:$//g"
. When /etc/ld.so.conf
has no paths listed in it. The output from the previous command is
/lib
/usr/lib
I figured that it searches /lib
first and then /usr/lib
. When I add a new path, such as /usr/local/lib
, to /etc/ld.so.conf
and then remake /etc/ld.so.cache
, the output from ldconfig -v | grep -v "^"$'\t' | sed "s/:$//g"
becomes
/usr/local/lib
/lib
/usr/lib
I find this strange because if I am correct that the order that the listed directories are searched in is from top to bottom, then additional directories are searched before /lib
and /usr/lib
. That the additional directories are searched before the trusted directories is not strange on its own, but when /lib
is searched before /usr/lib
, that is strange because /bin
& /sbin
are searched after /usr/bin
& /usr/sbin
in PATH
.
Even if the paths listed by ldconfig -v | grep -Ev "^"$'\t' | sed "s/:$//g"
were searched from bottom to top, it would still be a skewed ordering because additional directories would be searched after the trusted ones while /lib
would be searched after /usr/lib
.
So, what is the order that ld.so
searches paths for libraries in? Why is /lib
searched before /usr/lib
? If it's not, then why are additional directories searched after /lib
?
Asked by Melab
(4328 rep)
May 27, 2017, 03:07 PM
Last activity: May 14, 2025, 10:57 AM
Last activity: May 14, 2025, 10:57 AM