- publishing free software manuals
An Introduction to GCC - for the GNU compilers gcc and g++
by Brian J. Gough, foreword by Richard M. Stallman
Paperback (6"x9"), 144 pages
ISBN 0954161793
RRP £12.95 ($19.95)

"A wonderfully thorough guide... well-written, seriously usable information" --- Linux User and Developer Magazine (Issue 40, June 2004) Get a printed copy>>>

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:


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:

  1. command-line options -I and -L, from left to right
  2. directories specified by environment variables, such as C_INCLUDE_PATH (for C programs), CPLUS_INCLUDE_PATH (for C++ programs) and LIBRARY_PATH
  3. default system directories

In day-to-day usage, directories are usually added to the search paths with the options -I and -L.

ISBN 0954161793An Introduction to GCC - for the GNU compilers gcc and g++See the print edition