Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I share a precompiled header between projects to reduce compile time?

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?

like image 466
David Avatar asked Dec 27 '12 01:12

David


People also ask

What is the purpose of a precompiled header?

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.

Do I need precompiled headers?

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.

How do I not use precompiled headers?

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.

What is Stdafx H?

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.


1 Answers

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.

like image 191
David Avatar answered Nov 15 '22 03:11

David