C++ Header Compile Times
The cluster discusses challenges with C++ header files causing long compile times due to repetitive parsing of implementations in headers, the popularity of header-only libraries, and mitigations like precompiled headers and modules.
Activity Over Time
Top Contributors
Keywords
Sample Comments
Unless they use pre compiled headers.
Still using header files in the 22nd century?
I’m a C noob, so why aren’t header only files the norm? Seems a lot easier to deal with then a split header and c file
Isn't this the reason precompiled headers are a thing?
sadly no, modules won't solve this problem. Yes you can write your implementation in a single module but it'll behave as if you were writing them in a .h file. That means that changing a single number in a module will trigger a recompilation of all the dependent modules. At the end of the day you end up with slower compile times for small changes. I was hoping to finally be able to be done with header files but no.. another missed opportunity for C++. Perhaps future C++ compilers will
Not currently. I think it can be largely attributed to header files, for which we currently have no solution in modern C++. Think about what your code would look like if you expanded all #includes of a single file, each containing entire class definitions that need to be parsed.One of the proposals for the next C++ standard is for modules, which would allow better symbol importing and would largely boost compilation speeds, among other benefits.
Welcome to modern c++, where everything is a header file and compile times don't matter.
Are we speaking in a general sense here? Because the root of this is headers needing to be compiled with (almost) every use in C++. We could get rid of that while maintaining the same functionality. It's not a very bold claim unless there's a requirement of "no significant language changes"
Pre-compiled headers, binary libraries, avoid header only libraries, if lucky to be on latest clang/VC++, modules.
In this case I really have to nitpick about the use of "C/C++": This specific problem really only exists in C++, because there it is common to put implementation code into headers via inline and template functions (worst example is the C++ stdlib), while in C you only put declarations into headers, and just parsing a few hundred lines of struct and function declarations won't blow up your build times (while just including a common C++ stdlib header like pulls i