Click here to Skip to main content
Click here to Skip to main content

Reducing VisualStudio / C++ built times dramatically

By , 14 Jan 2010
Rate this:
Please Sign up or sign in to vote.
When working with large C++ projects in Visual Studio built times can become a problem. I'm working on a project with 140000+ lines of code split into 23 Projects (1 Main App; 3 libs; 19 DLL's). Depending on the CPU speed built times could exceed 10 Minutes. May not sound much but if you have to change the framework often rebuilds are required several times a day and the total compilation time per day can quickly become a problem.
The usual time safers like precompiled headers, excessive use of forward declaration and building with support for multiple cores (/MP) were already in place. Time to try a solution I wouldn't touch under normal circumstances: Including all cpp files into a single compilation unit. (Kinda like precompiled headers just for the cpp files...)
Here is how it works:
  1. Create a few cpp files that include all your projects cpp files. For instance one to include all your gui code, one for the data handling, one for all utility files. Add those files to your project.
  2. Set the original cpp files to "exclude from build" in the project settings; Only your new include files shall be set to compile.
Instead of compiling a large number of small files you end up compiling a small number of large files. This is significantly faster.
  • You can continue working with your solution normally, all your files are still listed, they are just marked as "excluded from build"
  • Built times will decrease dramatically
  • Name collisions are possible when using global variables.
  • Partial build times will go up. This is managable if you don't put all your cpp files into a single include file. (use two or three)
This was'nt my idea so the credit goes to Noel Llopis from the gamesfromwithin blog. The original article is here:
Read it to learn more about the background. I found this approach very helpfull for my case. Thanks to the original author for his in depth investigations into this.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Software Developer
Germany Germany
No Biography provided

Comments and Discussions

GeneralSpeedup VS2008 PinmemberJimmyO27-Oct-10 8:35 
if you have only 2 GB RAM, you can also simple speedup build times.
put 4 GB into your system.
Sample: Quard Core 2 GB.
Build our application need 22 min.
Linking need 2,5 min.
After upgrade RAM:
Building need 10,5 min.
Linking need 0,5 min (30 sec.)

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140421.2 | Last Updated 14 Jan 2010
Article Copyright 2010 by iberg
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid