Precompiled Header Files

Mac OS X’s Developer Tools support and provide extensive documentation on building and using precompiled header files. This section highlights a few of the issues that may be of interest to Unix developers new to Mac OS X when it comes to working with precompiled headers.

Precompiled header files are binary files that have been generated from ordinary C header files and that have been preprocessed and parsed using cpp-precomp. When such a precompiled header is created, both macros and declarations present in the corresponding ordinary header file are sorted, resulting in a faster compile time, a reduced symbol table size, and consequently, faster lookup. Precompiled header files are given a .p extension and are produced from ordinary header files that end with a .h extension. There is no risk that a precompiled header file will get out of sync with the .h file, because the compiler checks the timestamp of the actual header file.

When using precompiled header files, you should not refer to the .p version of the name, but rather to the .h version in the #include directive. If a precompiled version of the header file is available, it will be used automatically; otherwise, the real header file (.h) will be used. So, to include foo.p, you would specify foo.h. The fact that cc is using a precompiled header is totally hidden from you.

In addition to checking the timestamp, the preprocessor also checks whether or not the current context is the same as the context ...

Get Mac OS X for Unix Geeks 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.