Datasheet

The GNU compiler system’s driver program, gcc (which you used in the preceding programming
example), is typically located in
/usr/bin or /usr/local/bin, but it will run various compiler-
support applications from another location. This location is specified when you compile the compiler
itself and varies with the host computer type. For Linux systems, this location might be a version-
specific subdirectory of
/usr/lib/gcc/. On one of the author’s machines at the time of writing it is
/usr/lib/gcc/i586-suse-linux/4.1.3. The separate passes of the GNU C/C++ compiler, and
GNU-specific header files, are stored here.
Header Files
For programming in C and other languages, you need header files to provide definitions of constants and
declarations for system and library function calls. For C, these are almost always located in
/usr/include
and subdirectories thereof. You can normally find header files that depend on the particular incarnation of
Linux that you are running in
/usr/include/sys and /usr/include/linux.
Other programming systems will also have header files that are stored in directories that get searched
automatically by the appropriate compiler. Examples include
/usr/include/X11 for the X Window
System and
/usr/include/c++ for GNU C++.
You can use header files in subdirectories or nonstandard places by specifying the
-I flag (for include)
to the C compiler. For example,
$ gcc -I/usr/openwin/include fred.c
will direct the compiler to look in the directory /usr/openwin/include, as well as the standard places,
for header files included in the
fred.c program. Refer to the manual page for the C compiler (man gcc) for
more details.
It’s often convenient to use the
grep command to search header files for particular definitions and func-
tion prototypes. Suppose you need to know the name of the
#defines used for returning the exit status
from a program. Simply change to the
/usr/include directory and grep for a probable part of the
name like this:
$ grep EXIT_ *.h
...
stdlib.h:#define EXIT_FAILURE 1 /* Failing exit status. */
stdlib.h:#define EXIT_SUCCESS 0 /* Successful exit status. */
...
$
Here grep searches all the files in the directory with a name ending in .h for the string EXIT_. In this
example, it has found (among others) the definition you need in the file
stdlib.h.
Library Files
Libraries are collections of precompiled functions that have been written to be reusable. Typically, they con-
sist of sets of related functions to perform a common task. Examples include libraries of screen-handling
functions (the
curses and ncurses libraries) and database access routines (the dbm library). We show you
some libraries in later chapters.
9
Chapter 1: Getting Started
47627c01.qxd:WroxPro 9/28/07 8:56 PM Page 9