views:

675

answers:

6

Hello All,

Back a long time ago I used to use pre-compiled headers: a. to speed compilation and b. because I supported multiple development tools like CodeWarrior, MPW, VS, ProjectBuilder, gcc, intel compilers, etc, etc.

Now I have a Mac Pro with 32gb of RAM.

Now I use just CMake.

So do we really need pre-compiled headers anymore?

Are there obvious benefits that I just dont see/know?

How can one make a cross-platform pre-compiled header? Maybe that would simplify my life too.

+4  A: 

I think that your question really depends on the size of the project you are compiling. There are some really large projects out there where precompiled headers do make a huge difference.

So, my answer is: it depends..

But if using them makes you life miserable for some reason or another (i.e. portability) and your project is not incredibly large.. I'd say skip them.

Miky Dinescu
A: 

The advantage of precompiled headers is that the huge system library header files and other files that do not change at all or infrequently only have to be parsed once per build.

As all C compilers (that I know of) work on every .c file seperately, skipping the "known" part of the includes can have a huge impact on compile time.

They are not a portability issue either, you can compile a project using stdafx.h/cpp with GCC just fine, the only problem is that the compilation time might go up because not everything in stdafx.h is needed in every compilation unit.

Timbo
MSVC works on multiple source files physically, but keeps them logically separate.
MSalters
A: 

The only obvious benefit is a slight decrease in compilation time. I generally don't use them. On most of my projects, the compilation times are not that bad (e.g. usually less than a few minutes).

Unless your project is enormous, they usually do more harm than good. (They are highly compiler dependent.)

Zifre
+1  A: 

It's still useful to use precompile header for at least two reasons :
1) A lot of people don't have a Mac Pro with 32 GB RAM, lucky man !
2) It's a way to limit inclusion in *.h
The only way that I know to make cross-platform pre-compiled header is to work with Qt and its cross platform project file : the PRO file !

Matthieu
pre-compiled headers end up using more ram... I don't understand your comment.
Marius
I mean a powerful machine, RAM is just a descriptive example... Obviously, RAM doesn't make compilation faster !
Matthieu
+6  A: 

There is no such thing as a build that is "Fast enough". Some of the TDD folk get upset if their build takes longer than a few seconds. I've worked on projects with hours of compilation time that we halved (or better) by working with pre-compiled headers the right way.

However, the preferred solution remains that compilation times never get that far out of hand, by controlling the physical dependencies of the code.

For more information read The Care and Feeding of Pre-compiled Headers

MadKeithV
+1  A: 

I'm always turning it off. I've run into more problems than good with them on the projects I've worked on. Many subtle bugs came up that could be tracked down to a precompiled header that did not get recompiled for some reason. Maybe it's better in current VS incarnations.

Jim Buck