What is the PCH file format?
A .pch file is a precompiled header - a binary compiler cache generated automatically during the build process. Rather than re-parsing large header files such as the Windows SDK or stdafx.h on every compilation unit, the compiler serializes its internal state - symbol tables, AST nodes, macro definitions, include-guard flags - into a .pch snapshot. Subsequent compilation units load that snapshot directly, cutting build times dramatically for large C and C++ projects.
MSVC produces .pch files via the /Yc compiler flag, typically from a dedicated stub source file named pch.cpp or stdafx.cpp. Clang stores its precompiled headers as a compressed LLVM bitstream embedded inside a native object file in a section named __clangast. GCC's equivalent uses the .gch extension rather than .pch.
The format is entirely compiler-internal - proprietary, binary, and non-transferable between machines. A .pch file is invalidated whenever the compiler version, compiler flags, or any included header changes; the build system regenerates it automatically. Typical sizes range from 10 MB to over 200 MB when the Windows SDK headers are included.
Users never create or open .pch files manually. Deleting one is safe - the next build recreates it, and a clean rebuild is the standard remedy for persistent PCH-related errors. C++20 Modules partially reduce reliance on precompiled headers in new codebases, but .pch remains the dominant compile-speed mechanism in existing C and C++ projects.
Security & safety
RISK: LOWA .pch is an internal compiler build artifact. It cannot run code and is not executed by the OS. No meaningful attack vector; the file is generated locally by the build system and is machine-specific.
Format details
in a nutshell- Apple Xcode Prefix Header - Xcode (pre-Swift) used a .pch prefix header (source file, not binary) to precompile Objective-C headers; the concept is the same but the file is a text header, not the binary output.
Programs that open PCH files
Technical details
deep spec| File type | Binary compiler cache (serialized AST and symbol state) |
| Encoding | Binary (compiler-internal representation) |
| Byte order | Little-endian (MSVC on x86/x64); target-dependent (Clang) |
| Container | Proprietary binary blob (MSVC); COFF/ELF/Mach-O object file with embedded __clangast section (Clang) |
| Compression | None (MSVC); compressed LLVM bitstream, zlib-based (Clang) |
| Typical size | 10 MB - 200 MB; Windows SDK PCH commonly 50-200 MB |
| MSVC generation flag | /Yc creates the PCH; /Yu consumes it in subsequent compilation units |
| Default source file | stdafx.cpp or pch.cpp in MSVC projects |
| Machine specificity | Not transferable between machines; MSVC PCH includes host-specific address information |
| Invalidation | Automatically regenerated when compiler version, flags, or any included header changes |
| GCC equivalent | .gch extension (GCC precompiled headers do not use .pch) |
| Version detection | MSVC embeds internal signature; rejects stale PCH files on version or flag mismatch |
| C++20 successor | C++20 Modules (.ifc in MSVC) partially replace PCH in new codebases |
| Associated OS | Windows (MSVC), macOS (Xcode and Clang), Linux (Clang and GCC) |
| Released | 1988 (Microsoft C Compiler 6.0 for MS-DOS, first PCH implementation); mainstream adoption with MSVC for Windows in the 1990s |
| Latest version | N/A - format is internal per compiler; MSVC PCH is regenerated by each compiler version |
| Specification | learn.microsoft.com |
Community Q&A
asked by usersNo questions yet - be the first to ask about PCH files.