3
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
4
<title>Precompiled Headers</title>
5
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
6
<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
7
<link rel="start" href="../../index.html" title="Boost.Build V2 User Manual">
8
<link rel="up" href="../tasks.html" title="Chapter�5.�Common tasks">
9
<link rel="prev" href="../builtins/raw.html" title="Custom commands">
10
<link rel="next" href="generated_headers.html" title="Generated headers">
12
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td></tr></table>
15
<div class="spirit-nav">
16
<a accesskey="p" href="../builtins/raw.html"><img src="../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tasks.html"><img src="../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="generated_headers.html"><img src="../../../../doc/html/images/next.png" alt="Next"></a>
18
<div class="section" lang="en">
19
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
20
<a name="bbv2.reference.precompiled_headers"></a>Precompiled Headers</h2></div></div></div>
21
<p>Precompiled headers is a mechanism to speed up compilation
22
by creating a partially processed version of some header files,
23
and then using that version during compilations rather then
24
repeatedly parsing the original headers. Boost.Build supports
25
precompiled headers with gcc and msvc toolsets.</p>
26
<p>To use precompiled headers, follow these steps:</p>
27
<div class="orderedlist"><ol type="1">
28
<li><p>Create a header that includes big headers used by your project.
29
It's better to include only headers that are sufficiently stable —
30
like headers from the compiler, and external libraries. Please wrap
31
the header in <code class="computeroutput">#ifdef BOOST_BUILD_PCH_ENABLED</code>, so that
32
the potentially expensive inclusion of headers is not done
33
when PCH is not enabled. Include the new header at the top of your
34
source files.</p></li>
36
<p>Declare a new Boost.Build target for the precompiled header
37
and add that precompiled header to the sources of the target whose compilation
40
<pre class="programlisting">
41
cpp-pch pch : header.hpp ;
42
exe main : main.cpp pch ;</pre>
44
You can use the <code class="computeroutput">c-pch</code> if you want to use the precompiled
49
<p>The <code class="filename">pch</code> example in Boost.Build distribution
50
can be used as reference.</p>
51
<p>Please note the following:</p>
52
<div class="itemizedlist"><ul type="disc">
53
<li><p>The inclusion of the precompiled header must be the
54
first thing in a source file, before any code or preprocessor directives.
56
<li><p>The build properties used to compile the source files
57
and the precompiled header must be the same. Consider using
58
project requirements to assure this.
60
<li><p>Precompiled headers must be used purely as a way to
61
improve compilation time, not to save the number of <code class="computeroutput">#include</code>
62
statements. If a source file needs to include some header, explicitly include
63
it in the source file, even if the same header is included from
64
the precompiled header. This makes sure that your project will build
65
even if precompiled headers are not supported.</p></li>
68
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
69
<td align="left"></td>
70
<td align="right"><small></small></td>
73
<div class="spirit-nav">
74
<a accesskey="p" href="../builtins/raw.html"><img src="../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../tasks.html"><img src="../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="generated_headers.html"><img src="../../../../doc/html/images/next.png" alt="Next"></a>