http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54780



--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-10-02 
13:53:13 UTC ---

(In reply to comment #0)

> Next the script copies common.h to the main directory and compiles the sources

> again using the exact same compiler switches. What happens is that g++ does 
> not

> find the precompiled header, probably because it first looks in the source dir

> and finds common.h but not the corresponding pch and just stops looking. This

> makes the compilation very slow.



This is by design.  A header included as #include "common.h" looks in the

current dir first, so the compiler looks for ./common.h.gch, then for

./common.h, then stops because it's found.  The alternative would be to

continue searching *every* other directory looking for common.h.gch, which

would be *much* slower (there might be no PCH anywhere, so for projects that

don't use PCH it would mean checking every single directory for every single

header)



Maybe the solution you want is to use #include <common.h> and add -I. to the

compilation commands, ensuring that -Ipchdir comes before -I. because that will

not start with the current dir, and will look for pchdir/common.h.gch first and

will stop when found. Doing that makes all three steps in your script very

fast.

Reply via email to