DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
C compilation system

Searching for a header file

The first line of our sample program was:

   #include <stdio.h>
The format of that directive is the one you should use to include any of the standard header files that are supplied with the C compilation system. The angle brackets (< >) tell the preprocessor to search for the header file in the standard place for header files on your system, usually the /usr/include directory.

The format is different for header files that you have stored in your own directories:

   #include "header.h"
The double quotes (" ") tell the preprocessor to search for header.h first in the directory of the file containing the #include line, which will usually be your current directory, then in the standard place.

If your header file is not in the current directory, specify the path of the directory in which it is stored with the -I option to cc. For instance, if you have included both stdio.h and header.h in the source file test.c:

   #include <stdio.h>
   #include "header.h"
and header.h is stored in the directory ../defs, the command:
   $ cc -I../defs test.c
will direct the preprocessor to search for header.h first in the current directory, then in the directory ../defs, and finally in the standard place. It will also direct the preprocessor to search for stdio.h first in ../defs, then in the standard place. The only difference is that the current directory is searched only for header files whose name you have enclosed in quotation marks.

You can specify the -I option more than once on the cc command line. The preprocessor searches the specified directories in the order they appear on the command line. You can therefore specify multiple options to cc(CP) on the same command line:

$ cc -o prog -I../defs test.c


Next topic: Preparing your program for debugging
Previous topic: Commonly used cc command line options

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003