Examples of Multiple Initial Sequences for Precompiled C Headers

Here are four examples that show the interaction of configuration files options file(genPCH) and file(usePCH) and #pragma hdrfile directives:

Example 1

 #pragma hdrfile "wendy.pch"
 #include "h1.h"
 #include "h2.h"
 main () {}
Options Specified Behavior
file(genPCH)
file(usePCH)
The headers "h1.h" and "h2.h" are precompiled using the file "wendy.pch"
file(genPCH, dave.pch ) The compiler ignores the name specified with the option, because it is in conflict with the #pragma hdrfile directive. The compiler generates new headers in "wendy.pch", but does not use them.

Example 2

 #pragma hdrfile "wendy.pch"
 #include "h1.h"
 #pragma hdrstop
 #include "h2.h"
 main () {}
Options Specified Behavior
file(genPCH)
file(usePCH)
Only the header "h1.h" is precompiled, using the file "wendy.pch"
file(usePCH, frodo.pch ) The compiler ignores the name specified with the option, because it is in conflict with the #pragma hdrfile directive. The compiler looks for the precompiled headers in "wendy.pch", but does not generate new headers.

Example 3

 #include "h1.h"
 #pragma hdrstop
 #include "h2.h"
 main () {}
Options Specified Behavior
file(genPCH)
file(usePCH)
Only the header "h1.h" is precompiled, using the file "csetc.pch"
file(usePCH,doc.pch)
file(genPCH, gobo.pch
)
The compiler ignores the name specified with file(usePCH), and uses the file "gobo.pch", which is specified later. The compiler looks for precompiled headers in "gobo.pch" and regenerates them if they are not found or are out of date.

Example 4

 #pragma hdrstop
 #include "h1.h"
 main () {}
Options Specified Behavior
Any options No headers are precompiled, because there is no initial sequence: #pragma hdrstop occurs before the first #include directive.

Example of an Initial Sequence for Precompiled C Headers
Example Matching Initial Sequences for C Precompiled Headers



C Compilation
Precompiled C Headers
Organizing Your C Source for Precompiled Headers


Set Build Options
Build


C File Options