forked from OSchip/llvm-project
parent
fa0c645bae
commit
b48c6eb794
|
@ -431,50 +431,43 @@ headers vary between compilers, precompiled headers have been shown to be a
|
||||||
highly effective at speeding up program compilation on systems with very large
|
highly effective at speeding up program compilation on systems with very large
|
||||||
system headers (e.g., Mac OS/X).</p>
|
system headers (e.g., Mac OS/X).</p>
|
||||||
|
|
||||||
<p>Clang supports an implementation of precompiled headers known as
|
<h4>Generating a PCH File</h4>
|
||||||
<em>pre-tokenized headers</em> (PTH). Clang's pre-tokenized headers support most
|
|
||||||
of same interfaces as GCC's pre-compiled headers (as well as others) but are
|
|
||||||
completely different in their implementation. If you are interested in how
|
|
||||||
PTH is implemented, please see the <a href="PTHInternals.html">PTH Internals
|
|
||||||
document</a>.</p>
|
|
||||||
|
|
||||||
<h4>Generating a PTH File</h4>
|
<p>To generate a PCH file using Clang, one invokes Clang with
|
||||||
|
|
||||||
<p>To generate a PTH file using Clang, one invokes Clang with
|
|
||||||
the <b><tt>-x <i><language></i>-header</tt></b> option. This mirrors the
|
the <b><tt>-x <i><language></i>-header</tt></b> option. This mirrors the
|
||||||
interface in GCC for generating PCH files:</p>
|
interface in GCC for generating PCH files:</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
$ gcc -x c-header test.h -o test.h.gch
|
$ gcc -x c-header test.h -o test.h.gch
|
||||||
$ clang -x c-header test.h -o test.h.pth
|
$ clang -x c-header test.h -o test.h.pch
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<h4>Using a PTH File</h4>
|
<h4>Using a PCH File</h4>
|
||||||
|
|
||||||
<p>A PTH file can then be used as a prefix header when a
|
<p>A PCH file can then be used as a prefix header when a
|
||||||
<b><tt>-include</tt></b> option is passed to <tt>clang</tt>:</p>
|
<b><tt>-include</tt></b> option is passed to <tt>clang</tt>:</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
$ clang -include test.h test.c -o test
|
$ clang -include test.h test.c -o test
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>The <tt>clang</tt> driver will first check if a PTH file for <tt>test.h</tt>
|
<p>The <tt>clang</tt> driver will first check if a PCH file for <tt>test.h</tt>
|
||||||
is available; if so, the contents of <tt>test.h</tt> (and the files it includes)
|
is available; if so, the contents of <tt>test.h</tt> (and the files it includes)
|
||||||
will be processed from the PTH file. Otherwise, Clang falls back to
|
will be processed from the PCH file. Otherwise, Clang falls back to
|
||||||
directly processing the content of <tt>test.h</tt>. This mirrors the behavior of
|
directly processing the content of <tt>test.h</tt>. This mirrors the behavior of
|
||||||
GCC.</p>
|
GCC.</p>
|
||||||
|
|
||||||
<p><b>NOTE:</b> Clang does <em>not</em> automatically use PTH files
|
<p><b>NOTE:</b> Clang does <em>not</em> automatically use PCH files
|
||||||
for headers that are directly included within a source file. For example:</p>
|
for headers that are directly included within a source file. For example:</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
$ clang -x c-header test.h -o test.h.pth
|
$ clang -x c-header test.h -o test.h.cth
|
||||||
$ cat test.c
|
$ cat test.c
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
$ clang test.c -o test
|
$ clang test.c -o test
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>In this example, <tt>clang</tt> will not automatically use the PTH file for
|
<p>In this example, <tt>clang</tt> will not automatically use the PCH file for
|
||||||
<tt>test.h</tt> since <tt>test.h</tt> was included directly in the source file
|
<tt>test.h</tt> since <tt>test.h</tt> was included directly in the source file
|
||||||
and not specified on the command line using <tt>-include</tt>.</p>
|
and not specified on the command line using <tt>-include</tt>.</p>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue