Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a good CPU/PC setup to speed up intensive C++/templates compilation?

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?

like image 698
ApplePieIsGood Avatar asked Dec 17 '22 02:12

ApplePieIsGood


2 Answers

Are 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.

like image 62
Dean Harding Avatar answered Jan 04 '23 16:01

Dean Harding


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).

like image 34
kyoryu Avatar answered Jan 04 '23 15:01

kyoryu