Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions

  




 

 

3.1 Setting search paths

In the last chapter, we saw how to link to a program with functions in the C math library 'libm.a', using the short-cut option -lm and the header file 'math.h'.

A common problem when compiling a program using library header files is the error:

FILE.h: No such file or directory

This occurs if a header file is not present in the standard include file directories used by gcc. A similar problem can occur for libraries:

/usr/bin/ld: cannot find library

This happens if a library used for linking is not present in the standard library directories used by gcc.

By default, gcc searches the following directories for header files:

/usr/local/include/
/usr/include/

and the following directories for libraries:

/usr/local/lib/
/usr/lib/

The list of directories for header files is often referred to as the include path, and the list of directories for libraries as the library search path or link path.

The directories on these paths are searched in order, from first to last in the two lists above.(7) For example, a header file found in '/usr/local/include' takes precedence over a file with the same name in '/usr/include'. Similarly, a library found in '/usr/local/lib' takes precedence over a library with the same name in '/usr/lib'.

When additional libraries are installed in other directories it is necessary to extend the search paths, in order for the libraries to be found. The compiler options -I and -L add new directories to the beginning of the include path and library search path respectively.


 
 
  Published under the terms of the GNU General Public License Design by Interspire