Chapter 11. Libraries, Headers, and Frameworks
In the previous chapter, we gave an overview of the development tools that ship with Mac OS X and emphasized the compilation phase of building executable code. In this chapter, we’ll discuss the linking phase of building Unix-based software under Mac OS X: in particular, header files and libraries.
Header Files
There are two types of header files in Mac OS X:
- Ordinary header files
These header files are inserted into source code by a preprocessor prior to compilation. Ordinary header files have an .h extension.
- Precompiled header files
These header files have an .h.gch extension.
Header files serve four functions:
They contain C declarations.
They contain macro definitions.
They provide for conditional compilation.
They provide line control when combining multiple source files into a single file that is subsequently compiled.
Unix developers will find the ordinary header files familiar, since
they follow the BSD convention. The C preprocessor directive #include
includes a header file in a C source file. There are essentially three
forms of this syntax:
#include <
headername
.h>
This form is used when the header file is located in the directory /usr/include.
#include <
directory
/headername
.h>
This form is used when the header file is located in the directory /usr/include/
directory
, wheredirectory
is a subdirectory of /usr/include.#include "
headername
.h"
This form is used when the header file is located in a user or nonstandard directory. The file should ...
Get Mac OS X For Unix Geeks, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.