The 2.0 compiler includes a beta support for precompiled headers.
Precompiled code is useful during the development cycle to reduce compilation time, especially if:
- You always use a large body of code that changes infrequently.
- Your program comprises multiple modules, all of which use a standard set of include files and the same compilation options. In this case, all include files can be precompiled into one precompiled header.
The usage is very simple: create an include file called stdafx.inc, and place in it all the code, definitions, or include other headers you want to precompile, then include stdafx.inc file in your source file(s).
The compiler, while parsing the stdafx.inc header will create stdafx.pch binary file with the precompiled contents of the header. If the PCH file already exists, the compiler will compare last-modified time of all referenced files (stdafx.inc file and all files included from it). If you modify any referenced file, the PCH file will be recreated.
Example: create a project with two or more source files. Place the following line in all source files:
$include "windowssdk.inc"
It can be any other .inc file, but it should be really huge.
Save the project and compile. Notice how much time is required to compile the project (~1.5s * number of source files).
Now replace windowssdk with stdafx in all source files, create stdafx.inc file in project directory, open it in the editor and place the above line in it ($include windowssdk). Compile again and notice the boost.
For the first time (when the PCH file does not exists) or the PCH file is rebuild, it will take a bit longer to compile the project, because the compiler will access windowssdk.inc and all the referenced headers. For the second time, the project will be compiled in a second.
The name of include file "stdafx.inc" is reserved for precompiled headers. The current parser version (2.0) does not correctly handle SELECT, CASE, CASE&, DEFAULT keywords while creating/reading precompiled headers.
The precompiled header can be used without creating a project. The same INC+PCH file may be used for all projects or single-file programs, just place the INC and PCH file in some shared location.
Attached is a sample project with 4 source files - the content of windowssdk.inc is available in all source files.
See also disphelper integration (http://www.ionicwind.com/forums/index.php?topic=4489.msg35030)