Precompiled header
lastmod 2021-11-05created 2021-01-295 edits
In computer programming, a precompiled header is a (C or C++) header file that is compiled into an intermediate form that is faster to process for the compiler. Usage of precompiled headers may significantly reduce compilation time, especially when applied to large header files, header files that include many other header files, or header files that are included in many translation units.
GCH
The PCH feature has been supported since gcc-3.4. The basic idea of PCH is to reduce compile time by preprocessing (bundling into one) the header files commonly referenced by many source files.
For C++:
For C:
Compiling as above produces a fairly large stdafx.h.gch file. This file is the Pre-Compiled header. To use the Pre-Compiled header, all you need to do is add #include "stdafx.h" where you want it. That is, if stdafx.h.gch exists where the stdafx.h file is, the gch is checked first.
See also
- Prefix header
- GCC
- GCH
- GCC:DependencyHeaderFiles: list of dependency files.
Favorite site
- Wikipedia (en) article on Precompiled Headers
- wxWiki - Precompiled Headers 1
- Using PCH(Pre-Compiled Header) 2
- How to use GCC Precompiled header