You can also use the environment variable LD_LIBRARY_PATH
, which takes a colon-separated list of directories, to add to the link-editor's library search
path. In its most general form, LD_LIBRARY_PATH
takes two directory lists separated by a semicolon. The first list is searched before the lists supplied on the
command line, and the second list is searched after.
The following example shows the combined effect of setting LD_LIBRARY_PATH
and calling the link-editor with several -L occurrences:
$ LD_LIBRARY_PATH=dir1:dir2;dir3 $ export LD_LIBRARY_PATH $ cc -o prog main.c -Lpath1 ... -Lpath2 ... -Lpathn -lfoo |
The effective search path is dir1:dir2:path1:path2... pathn:dir3:/usr/ccs/lib:/usr/lib.
If no semicolon is specified as part of the LD_LIBRARY_PATH
definition, the specified directory list is interpreted after any -L options. In the following example the effective search path is path1:path2... pathn:dir1:dir2:/usr/ccs/lib:/usr/lib.
$ LD_LIBRARY_PATH=dir1:dir2 $ export LD_LIBRARY_PATH $ cc -o prog main.c -Lpath1 ... -Lpath2 ... -Lpathn -lfoo |
This environment variable can also be used to augment the search path of the runtime linker. See “Directories Searched by the Runtime Linker”. To prevent this environment variable from influencing the link-editor, use the -i option.