This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Precompile Headers. What is Best Practice?
- From: Ian Lance Taylor <iant at google dot com>
- To: John Carter <john dot carter at tait dot co dot nz>
- Cc: gcc-help at gcc dot gnu dot org
- Date: 05 Sep 2007 20:27:30 -0700
- Subject: Re: Precompile Headers. What is Best Practice?
- References: <Pine.LNX.4.64.0709061022390.5475@parore.tait.co.nz>
John Carter <john.carter@tait.co.nz> writes:
> Precompiled headers sound really tasty..., I've read the docs three
> times but I'm not sure I've quite digested it enough to do a large
> implementation. So I'm looking for some practical / standard practice
> guidance here.
Precompiled headers are a good idea on paper but note that in some
actual applications they turn out not to be faster, based on doing
actual timings.
> I'm always trying to trim a few seconds off the 2 hour compile time to
> it takes to compile & link all variants...
The most effective technique I know is to get a bunch of machines and
turn them into a distcc cluster. http://distcc.samba.org/. This
gives a near linear speedup in compilation time, though it doesn't
help with link time (PCH doesn't help with link time either, of
course).
> The docs say... "If the precompiled header file can't
> be used, it is ignored."
>
> Hmm. What does that mean? Does it mean...
It means that if the precompiled header was generated by a different
version of the compiler, it won't be used. Precompiled header files
are compiler version specific.
> This rule also takes some digesting...
> * Only one precompiled header can be used in a particular
> compilation.
>
> * A precompiled header can't be used once the first C token is seen.
> You can have preprocessor directives before a precompiled header;
> you can even include a precompiled header from inside another
> header, so long as there are no C tokens before the `#include'.
>
> Do you go around making sure that the (recursively) fattest .h is at the start?
> Or
> just hope that some speed up is better than nothing?
You create a single .h file which includes all your other .h files.
You precompile that file. You use the -include option to
automatically include it first in any compilation.
Ian