I have nearly 200 projects in Visual Studio and it takes too long to build them all. I notice that building stdafx.cpp (the precompiled headers) for each project is slow. I'm using the same header for every project, so why do I have to build it ~200 times? How can I build it once and share between projects?
Precompiled headers (PCH) are a performance feature supported by some compilers to compile a stable body of code, and store the compiled state of the code in a binary file. During subsequent compilations, the compiler will load the stored state, and continue compiling the specified file.
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 turn off precompiled headersSelect the Configuration properties > C/C++ > Precompiled Headers property page. In the property list, select the drop-down for the Precompiled Header property, and then choose Not Using Precompiled Headers.
The file stdafx. h is usually used as a precompiled header file. Precompiled headers help to speed up compilation when a group of files in a project do not change.
This question has been asked before, but Visual Studio has changed.
In Visual Studio 2008, it's possible to share the precompiled header with some hackery. Designate one project to build the PCH, and have every other project depend upon it (Project Dependencies). Ensure that you have only one stdafx.h and that every project can see it with #include "stdafx.h" (Additional Include Directories). Set every client project to use the masters PCH file (Precompiled Header File). Now use xcopy to copy the master's .pdb and .idb into each client output directory. You'll have to set the master project to output a pdb with a different name (Output Files). See links above for more specifics.
In Visual Studio 2010 and Visual Studio 2012 there's no known way to share PCH files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With