Arvind Haran
Arvind Haran

Reputation: 720

Compiling large header files C++

My code is organized as

//LARGEHEADER.H

class LARGE {

 ...
}

//SMALLER.H
#include "LARGEHEADER.H"
class SMALL: protected LARGE {
...
}

//and in each of A.C, B.C, C.C ...
#include "SMALLER.H"
void f() {
 ...
}

Now LARGEHEADER.H is in the order of 10 MB. While trying to compile this setup it seems to take up a lot of time and memory and my final executable is close to 90 MB. Please point out to me what I am doing wrong. How can I speed up my compilation with this setup.

Upvotes: 0

Views: 991

Answers (1)

Arvind Haran
Arvind Haran

Reputation: 720

Thanks for suggesting the solutions of pre-compiled headers. Pre-compiling headers is an optimization strategy which does not address the root cause of the problem, which is coding style. Referring to this article

Why does C++ compilation take so long?

Including a large header file in multiple source/header files will cause the compilation to blow up (generate debug/symbol info for each includer). I re-organized the code to remove such dependencies.

Upvotes: 1

Related Questions