This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Precompile Headers. What is Best Practice?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]