I currently have a machine with an Opteron 275 (2.2Ghz), which is a dual core CPU, and 4GB of RAM, along with a very fast hard drive. I find that when compiling even somewhat simple projects that use C++ templates (think boost, etc.), my compile times can take quite a while (minutes for small things, much longer for bigger projects). Unfortunately only one of the cores is pegged at 100%, so I know it's not the I/O, and it would seem that there is no way to take advantage of the other core for C++ compilation?
views:
147answers:
3Are you using pre-compiled headers? They typically provide the biggest compilation speed boost I get with my C++ projects.
Also, depending on your compiler, you can enable multi-thread compiling. For example, with Visual C++, it's the /MP switch (see here for details), though enabling /MP isn't always possible, depending on what other command-line options you use.
Compile time problems with templates are often link problems, rather than compilation problems.
Using templates internally in your .cpp files, but making sure that the headers don't actually include the template, is a good way to fix those. That can be done by either forward declaring the class, or wrapping your implementation class in an abstract base class that just declares the public members (the Pimpl Idiom, basically).
For taking advantage of multi-thread compiling with Makefile-based systems, take a look at the -j switch, the usual recommendation is to invoke
make -j<number of cores + 1>