This question is perhaps somehow odd, but how can I speed up g++ compile time? My C++ code heavily uses boost and templates. I already moved as much as possible out of the headers files and use the -j option, but still it takes quite a while to compile (and link).
Are there any tools out there which analyse my code and point out bottle-necks for the compiler? Or can one somehow profile the compiler running on my code? This would be really nice, because sometimes I have the impression, that I spent too much time staring at the compiler console log ...
C++ in general is slow to compile because of the ancient include mechanism, which causes the compiler to recursively re-parse every header with all its declarations and definitions and all that's included for every translation unit. Templates just build on that "feature".
The reason templates are considered faster is that they are visible to the compiler.
All the template parameters are fixed+known at compile-time. If there are compiler errors due to template instantiation, they must be caught at compile-time!
What has been most useful for me:
-j3
globally for make. Make sure your dependency graphs are correct in your Makefile, though, or you may have problems.-O0
if you're not testing execution speed or code size (and your computer is fast enough for you not to care much about the (probably small) performance hit).Here's what I've done to speed up builds under a very similar scenario that you describe (boost, templates, gcc)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With