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, wheredirectoryis 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access