File: precompiled_headers.html

package info (click to toggle)
boost-build 2.0-m12-2
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 8,692 kB
  • ctags: 6,963
  • sloc: ansic: 39,914; sh: 9,086; python: 6,120; xml: 5,524; cpp: 1,467; yacc: 456; asm: 353; makefile: 184
file content (77 lines) | stat: -rw-r--r-- 4,485 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Precompiled Headers</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
<link rel="start" href="../../index.html" title="Boost.Build V2 User Manual">
<link rel="up" href="../tasks.html" title="Chapter5.Common tasks">
<link rel="prev" href="../builtins/raw.html" title="Custom commands">
<link rel="next" href="generated_headers.html" title="Generated headers">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<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>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="bbv2.reference.precompiled_headers"></a>Precompiled Headers</h2></div></div></div>
<p>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.</p>
<p>To use precompiled headers, follow these steps:</p>
<div class="orderedlist"><ol type="1">
<li><p>Create a header that includes big headers used by your project.
        It's better to include only headers that are sufficiently stable &#8212;
        like headers from the compiler, and external libraries. Please wrap
        the header in <code class="computeroutput">#ifdef BOOST_BUILD_PCH_ENABLED</code>, 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.</p></li>
<li>
<p>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:
        </p>
<pre class="programlisting">
cpp-pch pch : header.hpp ;
exe main : main.cpp pch ;</pre>
<p>
        You can use the <code class="computeroutput">c-pch</code> if you want to use the precompiled
        header in C programs.
        </p>
</li>
</ol></div>
<p>The <code class="filename">pch</code> example in Boost.Build distribution
      can be used as reference.</p>
<p>Please note the following:</p>
<div class="itemizedlist"><ul type="disc">
<li><p>The inclusion of the precompiled header must be the
        first thing in a source file, before any code or preprocessor directives.
        </p></li>
<li><p>The build properties used to compile the source files 
        and  the precompiled header must be the same. Consider using 
        project requirements to assure this.
        </p></li>
<li><p>Precompiled headers must be used purely as a way to
        improve compilation time, not to save the number of <code class="computeroutput">#include</code>
        statements. If a source file needs to include some header, explicitly include
        it in the source file, even if the same header is included from
        the precompiled header. This makes sure that your project will build
        even if precompiled headers are not supported.</p></li>
</ul></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><small></small></td>
</tr></table>
<hr>
<div class="spirit-nav">
<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>
</div>
</body>
</html>