Boost C++ Libraries

PrevUpHomeNext

Precompiled Headers

Precompiled headers is a mechanism to speed up compilation by creating a partially processed version of some header files, and then using that version during compilations rather then repeatedly parsing the original headers. Boost.Build supports precompiled headers with gcc and msvc toolsets.

To use precompiled headers, follow the following steps:

  1. Create a header that includes headers used by your project that you want precompiled. It is better to include only headers that are sufficiently stable — like headers from the compiler and external libraries. Please wrap the header in #ifdef BOOST_BUILD_PCH_ENABLED, so that the potentially expensive inclusion of headers is not done when PCH is not enabled. Include the new header at the top of your source files.

  2. Declare a new Boost.Build target for the precompiled header and add that precompiled header to the sources of the target whose compilation you want to speed up:

    cpp-pch pch : pch.hpp ;
    exe main : main.cpp pch ;
    

    You can use the c-pch rule if you want to use the precompiled header in C programs.

The pch example in Boost.Build distribution can be used as reference.

Please note the following:


PrevUpHomeNext