3.1.3 Extended search paths
Following the standard Unix convention for search paths, several
directories can be specified together in an environment variable
as a colon separated list:
DIR1:DIR2:DIR3:...
The directories are then searched in order from left to right. A single
dot '.' can be used to specify the current directory.(9)
For example, the following settings create default include and link
paths for packages installed in the current directory '.' and the
'include' and 'lib' directories under '/opt/gdbm-1.8.3'
and '/net' respectively:
$ C_INCLUDE_PATH=.:/opt/gdbm-1.8.3/include:/net/include
$ LIBRARY_PATH=.:/opt/gdbm-1.8.3/lib:/net/lib
For C++ programs, use the environment variable CPLUS_INCLUDE_PATH
instead of C_INCLUDE_PATH
.
To specify multiple search path directories on the command line, the
options -I
and -L
can be repeated. For example, the
following command,
$ gcc -I. -I/opt/gdbm-1.8.3/include -I/net/include
-L. -L/opt/gdbm-1.8.3/lib -L/net/lib .....
is equivalent to the environment variable settings given above.
When environment variables and command-line options are used together
the compiler searches the directories in the following order:
- command-line options
-I
and -L
, from left to right
- directories specified by environment variables, such as
C_INCLUDE_PATH
(for C programs), CPLUS_INCLUDE_PATH
(for C++ programs) and LIBRARY_PATH
- default system directories
In day-to-day usage, directories are usually added to the search paths
with the options -I
and -L
.