How to Use #Include "Pch.H" Instead of #Include "Stdafx.H" as My Precompile Header in Visual Studio C++

What is pch.h and why is it needed to be included as the first header file?

pch stands for precompiled header.

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.

To reduce compilation times, some compilers allow header files to be compiled into a form that is faster for the compiler to process. This intermediate form is known as a precompiled header, and is commonly held in a file named with the extension .pch or similar, such as .gch under the GNU Compiler Collection.

In Visual Studio, precompiled header is usually named "pch.h" (for console based applications), but it is possible to use different name, or not use it at all. Which file would be precompiled header, if any, is determined by projects settings.

If the precompiled header file is "pch.h" and the compile option is /Yu, Visual Studio will not compile anything before the #include "pch.h" in the source file; it assumes all code in the source up to and including that line is already compiled.

Precompiled headers C++ can't rename pch.h

Adjust the name of the precompiled header file in the Project Properties under Configuration Properties -> C/C++ -> Precompiled Headers.
Note that pch.cpp has property to generate precompiled header.
Basically you may set the properties if and what precompiled header you use differently for each file in your project.



Related Topics



Leave a reply



Submit