8

In my case, it seems as if LD_LIBRARY_PATH is set to the empty string. But all standard system tools still work fine, so I guess the dynamic linker checks for that case and uses some default for LD_LIBRARY_PATH in that case.

What is that default value? I guess it at least includes /usr/lib but what else? Is there any good systematic way in figuring out the standard locations where the dynamic linker would search?

This question is slightly different from what paths the dynamic linker will search in. Having a default value means, that it will use the value of LD_LIBRARY_PATH if given, or if not given, it will use the default value - which means, it will not use the default value if LD_LIBRARY_PATH is provided.

marked as duplicate by Stephen Kitt, xhienne, daisy, countermode, Sparhawk Mar 28 '17 at 11:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

17

The usual dynamic linker on Linux uses a cache to find its libraries. The cache is stored in /etc/ld.so.cache, and is updated by ldconfig which looks on the paths it’s given in /etc/ld.so.conf (and nowadays typically files in /etc/ld.so.conf.d).

So there is no default value for LD_LIBRARY_PATH, default library lookup doesn’t need it at all. If LD_LIBRARY_PATH is defined, then it is used first, but doesn’t disable the other lookups (which also include a few default directories).

The ld.so(8) manpage has the details:

If a shared object dependency does not contain a slash, then it is searched for in the following order:

  • Using the directories specified in the DT_RPATH dynamic section attribute of the binary if present and DT_RUNPATH attribute does not exist. Use of DT_RPATH is deprecated.

  • Using the environment variable LD_LIBRARY_PATH (unless the executable is being run in secure-execution mode; see below). in which case it is ignored.

  • Using the directories specified in the DT_RUNPATH dynamic section attribute of the binary if present.

  • From the cache file /etc/ld.so.cache, which contains a compiled list of candidate shared objects previously found in the augmented library path. If, however, the binary was linked with the -z nodeflib linker option, shared objects in the default paths are skipped. Shared objects installed in hardware capability directories (see below) are preferred to other shared objects.

  • In the default path /lib, and then /usr/lib. (On some 64-bit architectures, the default paths for 64-bit shared objects are /lib64, and then /usr/lib64.) If the binary was linked with the -z nodeflib linker option, this step is skipped.

If LD_LIBRARY_PATH is empty, it is ignored. If it is set to empty values (with LD_LIBRARY_PATH=: for example), those empty values are interpreted as the current directory.

Not the answer you're looking for? Browse other questions tagged or ask your own question.