0

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.

Arvind Haran
  • 710
  • 7
  • 14
  • 1
    I would humbly suggest that a 10mb header is quite over size. Regardless, can't you precompile your headers in gcc? – KevinDTimm Nov 19 '15 at 20:38
  • 1
    Possible duplicate of [Precompiled Headers in Header Files](http://stackoverflow.com/questions/11403211/precompiled-headers-in-header-files) – KevinDTimm Nov 19 '15 at 20:39
  • What's the point of seprating LARGE and SMALL headers if SMALL always includes LARGE? – SergeyA Nov 19 '15 at 20:43
  • @KevinDTimm Thanks for recommending Precompiled headers. I'll look into that – Arvind Haran Nov 19 '15 at 20:44
  • @SergeyA : I am working on some legacy code which is structured that way. So changing that would be the last resort (if it does help speed up compilation) – Arvind Haran Nov 19 '15 at 20:45

1 Answers1

1

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.

Arvind Haran
  • 710
  • 7
  • 14