Directories are searched in the order they appear on the command line. The directories specified on the command line are scanned before the default directories. All -L options apply to all -l options, regardless of the order in which the options are displayed. LD_LIBRARY_PATH can also be used to supplement the library search path. Directory search stops in the first directory containing the corresponding library.
LD_LIBRARY_PATH is more complicated:
LD_LIBRARY_PATH
A list of directories to search for libraries specified in -l. Multiple directories are separated by a colon. In most cases, the general case, it will contain two lists of directories, separated by semicolons:
dirlist1; dirlist2
If ld is called with any number of occurrences of -L, as in:
ld . . . -Lpath1 . . . -Lpathn . . .
then ordering the search path:
dirlist1 path1 . . . pathn dirlist2 LIBPATH
When the directory list does not contain a semicolon, this is interpreted as dirlist2.
LD_LIBRARY_PATH . , LD_LIBRARY_PATH , , , .
.
user405725