Archive for the ‘gcc/g++’ Category

Speed Up Your Compilation Times

Tuesday, October 23rd, 2007

For those who may have missed a couple of these, here is an index to the Speed Up Your Compilation Times series:

Speed Up Your Compilation Times Part Three: Using distcc

Monday, October 22nd, 2007

This is one of those projects that is just so damn cool that even if you don’t use it you should still know about it. Have a bunch of machines around you? Want faster compile times? Use distcc. As you might gather from the name, distcc allows you to do distributed builds using gcc.

Essentially you install and start distcc on each machine, tell distcc on the main machine which machines to use, and run your build with distcc. The magic that is distcc takes care of the rest. I know it sounds too simple for something that seems so complicated but that’s the beauty of distcc: it really is that simple. Now go, and build things quickly.

Speed Up Your Compilation Times Part Two: Using ccache

Monday, October 22nd, 2007

In my last post I presented a technique for speeding up compilation times in a very limited number of a cases. The obvious question is then what about the rest of the time? Enter ccache. ccache is a compiler cache which is to say that if you request it to compile a file with the exact same preprocessor directives and compiler flags then the result from the cache will be used. I use this tool everyday and I highly recommend it.

For the nervous among you who are worried that ccache will produce results inconsistent with those from just using the compiler, I present this choice quote from the ccache site:

“The most important aspect of a compiler cache is to always produce exactly the same output that the real compiler would produce.”

If my recommendation and the assurances of the ccache site aren’t enough to convince you, I suggest you test it for yourself. I am positive you’ll find it works as advertised and that the decrease in compilation times will convince you to continue to use it.

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.