Reputation: 1383
On top of simpler syntax, Go claims that it largely achieves it's fast compilation speed by only importing dependencies once:
Go imports dependencies once for all files, so the import time doesn't increase exponentially with project size.
Is it possible to accomplish the same thing with C++ if you are careful with your design?
Say adding all includes to a single include file (that uses pragma once) that is included in all files? Or would it slow it down a lot as any change to any header would recompile everything instead of incremental?
I'm using LLVM. Still architecting the project.
Upvotes: 0
Views: 169
Reputation: 597051
Many compilers support "Precompiled Headers". So, even if a given header is used in multiple Translation Units, the compiler will compile it only the first time and cache the result for use in subsequent units. Check your compiler's documentation if this feature is supported and how to use it.
Upvotes: 0
Reputation: 38062
Yes it is possible to greatly reduce build time in C++ by carefully manage code structure.
One way to achieve that is to extensively use forward declarations. There is a tool which helps to achieve that: Include What You Use.
To make this more effective you have to also prevent compiler to generate default implementations of constructors, destructors and assignment operators in header file. So declaring them in header and then default define them in respective cpp can help to keep some classes forward declared in header file.
Other way to have build time speed up is to extensively use dependency inversion. But this is general rule for any language.
Upvotes: 2
Reputation: 1941
Usually a project consists of many .cpp files. A .cpp file with all it includes is a Translation Unit (TU). They are compiled separately and then linked into an executable or a dll.
Your solution would force every single TU despite however small its dependencies might be to include that huge header file. It will be included once, but once for every .cpp file in your project.
Most probably, it will make compilation slower. To let alone all the problems of such architecture - maintaining sanity of this codebase would be pain.
There is an insight in your question - probably what you want is precompiled headers. Carefully used in some cases they can shorten compilation time.
Upvotes: 2