Precompiled headers are a feature of the VisualAge C++ C compiler that you can use to reduce the time required to compile C programs. Using headers that have been precompiled during previous compilations eliminates the need to process header files that do not change between compilations.
To create precompiled headers, build with file(genPCH). To use them build with file(usePCH). Usually you use these options together. Alternatively you can use #pragma hdrfile in your source code.
If you always use file(genPCH) and file(usePCH) together, precompiled header files are created if they do not exist, and used if they do. When a source file is changed, the precompiled version is automatically regenerated.
Before you use precompiled headers, you must understand initial sequencesof #include directives:
VisualAge C++
relieves you of much of the overhead of header files for C++ and
compiles C++ incrementally. Precompiled headers are of no
advantage in C++ and are not supported.
How the
Compiler Uses Initial Sequences
The compiler generates a single precompiled object if the first
lines in a source file contain a valid initial sequence of
#include directives. Such an initial sequence of headers can
consist of the following:
When a header contains conditional compilation directives to prevent it from being included a second time, it is only counted once in the initial sequence, even if it appears multiple times.
The initial sequence ends when the source contains any construct not in the above list or #pragma hdrstop. If a #pragma hdrstop, or any other construct than a comment or preprocessing directive appears before the first #include in the source, the compiler cannot produce a precompiled header.
Any #include directives after the initial sequence are not precompiled. They must be compiled every time the source file is compiled.
In subsequent compiles, the precompiled object can be used in all compilation units that satisfy the following conditions:
How You
should Use Initial Sequences
Consider the following techniques to get the most benefit from
precompiled headers:
Examples
Example of an Initial
Sequence for Precompiled C Headers
Example Matching Initial Sequences
for Precompiled C Headers
Examples of Multiple Initial
Sequences for Precompiled C Headers
![]()
C Compilation
Organizing Your C Source for Precompiled
Headers
