From: Ted Kremenek
The high-level interface to generate a PTH file is the same as GCC's:
+The high-level clang driver supports an interface to use PTH files +that is similar to GCC's interface for precompiled headers.
+ +To generate a PTH file using clang, one invokes clang using +the -x lang-header option. This mirrors the interface in GCC for +generating PCH files:
$ gcc -x c-header test.h -o test.h.gch $ clang -x c-header test.h -o test.h.pth-
A PTH file can then be used as a prefix header when a -include -option is passed to clang:
+A PTH file can then be used as a prefix header when a +-include option is passed to clang:
$ clang -include test.h test.c -o test @@ -74,19 +83,19 @@ for headers that are directly included within a source file. For example: test.h since test.h was included directly in the source file and not specified on the command line using -include. -Using Pretokenized Headers (Low-level Interface)
+Using Pretokenized Headers with clang-cc (Low-level Interface)
The low-level Clang compiler tool, clang-cc, supports three command line options for generating and using PTH files.
-
To generate PTH files using clang-cc, use the option -emit-pth: - -
- $ clang-cc test.h -emit-pth -o test.h.pth -+To generate PTH files using clang-cc, use the option +-emit-pth: + +
$ clang-cc test.h -emit-pth -o test.h.pthThis option is transparently used by clang when generating PTH -files. Similarly, PTH files can be used as prefix headers using the -include-pth option:
+files. Similarly, PTH files can be used as prefix headers using the +-include-pth option:$ clang-cc -include-pth test.h.pth test.c -o test.s @@ -96,7 +105,8 @@ files. Similarly, PTH files can be used as prefix headers using the -includ (or "content" cache) of the source included by the original header file. This means that the contents of the PTH file are searched as substitutes for any source files that are used by clang-cc to process a -source file. This is done by specifying the -token-cache option: +source file. This is done by specifying the -token-cache +option:$ cat test.h @@ -173,7 +183,7 @@ also modifies those pages in memory, incurring the copy-on-write costs. The read-only nature of PTH can greatly reduce memory pressure for builds involving multiple cores, thus improving overall scalability. -Fast generation: PTH files can be generated in a small fraction +
Fast generation: PTH files can be generated in a small fraction of the time needed to generate GCC's PCH files. Since PTH/PCH generation is a serial operation that typically blocks progress during a build, faster generation time leads to improved processor utilization with parallel builds on