Library and package loading is done by the dlopen() function. When
dlopen() is passed an unqualified file name, it looks for it in one of
three groups of places.
- Any of the directories in the LD_LIBRARY_PATH environment variable.
LD_LIBRARY_PATH is a colon-separated list of directory names, just like the
PATH variable. (For security reasons, programs running as root (that is, either
being run by root or a setuid program owned by root) ignore
- The libraries listed in /etc/ld.so.conf. More accurately,
dlopen() looks in /etc/ld.so.cache, which is compiled from
/etc/ld.so.cache by the ldconfig program, usually at boot time.
Files that you add to a directory in /etc/ld.so.conf, or directories
that you add to /etc/ld.so.conf wont be seen by dlopen()
until you run ldconfig.
- /lib, then /usr/lib.
Any match stops the search: ie, if dlopen() finds the library in a
LD_LIBRARY_PATH directory, it wont look in /etc/ld.so.conf or
/usr/lib. Similarly, if dlopen() finds the library
in the first LD_LIBRARY_PATH, it wont look in the second or third