10.2 Precompiled headers
Precompiled headers PCH, are a Clang feature designed to improve Clang’s frontend performance. The basic idea is to create an AST (Abstract Syntax Tree) for a header file and reuse this AST during compilation for sources that include the header file.
Generating a precompiled header file is simple [5]. Suppose you have the following header file, header.h
:
1 #pragma once 2 3 void foo() { 4 }
Figure 10.1: Header file to be compiled to PCH
You can generate a PCH for it with the following command:
$ <...>/llvm-project/install/bin/clang -cc1 -emit-pch \ -x c++-header header.h \ ...