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.

➡️ Stable 0.5x Programming Languages
3,223
Comments
19
Years Active
5
Top Authors
#4447
Topic ID

Activity Over Time

2008
3
2009
6
2010
54
2011
40
2012
120
2013
69
2014
129
2015
123
2016
211
2017
162
2018
232
2019
325
2020
256
2021
260
2022
272
2023
357
2024
282
2025
312
2026
10

Keywords

AFAIK e.g DPU TypeScript XML d.ts ID HTTP TPU LLVM header headers files file library code libraries modules module unit

Sample Comments

giomasce Apr 5, 2018 View on HN

Unless they use pre compiled headers.

transfire Sep 11, 2016 View on HN

Still using header files in the 22nd century?

Decabytes Jan 7, 2024 View on HN

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

fizwhiz Jan 8, 2019 View on HN

Isn't this the reason precompiled headers are a thing?

kunos Jun 27, 2021 View on HN

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

looki Mar 4, 2016 View on HN

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.

greysphere Oct 28, 2020 View on HN

Welcome to modern c++, where everything is a header file and compile times don't matter.

Dylan16807 Jul 10, 2017 View on HN

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"

pjmlp May 29, 2025 View on HN

Pre-compiled headers, binary libraries, avoid header only libraries, if lucky to be on latest clang/VC++, modules.

flohofwoe Oct 25, 2022 View on HN

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