Specifying Library and Include File Information to Compilers

Normally, the C compiler uses certain "system directories" that it knows about during the compilation process. For example, it looks for include files like stdio.h in certain directories, and libraries in certain other directories. Some libraries, in particular the standard C library, are included by default; for others, e.g., the math library, you may have to specify that the library has to be used (e.g., for the math library, using the option -lm), but once this is done the system takes care of the actual work of figuring out where the library actually resides.

In the most general case, however, you may have to use libraries that are not known to the compiler. In such cases, in order to use the library routines you will also typically need some header files that define information about the data structures and/or functions provided by the library. In this case, there are three things that you need to specify when invoking the C compiler: (i) the library name(s); (ii) the list of directories to search for include files; and (iii) the list of directories to search for the libraries themselves:


Library name: -llibname (-l: lower case letter L)

include file directories: -I directory-name (-I: upper case letter i)

library code directories: -L directory-name

You do this by invoking the C compiler as follows. Suppose we have a library with the following characteristics:


Name: myIO

Include file directory: /home/cs352/FALL02/hw4_stuff

Library directory: /home/cs352/FALL02/hw4_stuff/lib

Then you invoke the C compiler as:

gcc ... -I /home/cs352/FALL02/hw4_stuff -L /home/cs352/FALL02/hw4_stuff/lib -lmyIO