Posts Tagged ‘Tricks’

Speed Up Your Compilation Times Part One: A Trick

Sunday, October 21st, 2007

Here’s a neat little trick that I’m not sure where I picked up. If you have to rebuild an entire project and it is fairly large give this a shot. Create one implementation file (.cpp) that includes all the other implementation files in the project like so:

#include "implementation_file1.cpp"
#include "implementation_file2.cpp"
#include "implementation_fileN.cpp"

And compile that file. This forces the entire project into one compilation unit and usually results in a fairly significant drop in compilation times (at least with gcc/g++). Be aware however that when a just a few files have changed then doing a partial rebuild with a build management tool like make is still faster. Though if you are doing a full rebuild then this trick is much faster.