Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: tiwag on November 02, 2005, 06:03:56 PM

Title: Precompiled Headers Strategy
Post by: tiwag on November 02, 2005, 06:03:56 PM
Why was this "Precompiled Headers Strategy" introduced and
why is the default mode "PCH in a directory alongside original header" ?

i always thought, that gcc does find the *.h.gch only in the same directory where the *.h file resides  :?
how can you tell gcc where to look for the PCH file *.h.gch ?
Title: Re: Precompiled Headers Strategy
Post by: mandrav on November 02, 2005, 06:59:11 PM
First of all, the "default" is subject to change.

Now, what each one does:

Well, that's about it :)
Title: Re: Precompiled Headers Strategy
Post by: Urxae on November 02, 2005, 07:04:52 PM
Note: I started typing this before Yiannis posted, but I'll just post anyway.

Quote from: tiwag on November 02, 2005, 06:03:56 PM
Why was this "Precompiled Headers Strategy" introduced and
why is the default mode "PCH in a directory alongside original header" ?

If you put it in a directory instead of directly next to the header, you can put multiple files in there. This comes in handy for files that are precompiled in different targets (with different compiler options). For instance, in Code::Blocks itself that might just make sdk/sdk_precomp.h unnecesary: you could add sdk/sdk.h to the 'sdk' target as well, and the precompiled headers would be sdk/sdk.h.gch/src and sdk/sdk.h.gch/sdk. (EDIT: I just ran a diff and sdk.h doesn't #include <uservarmanager.h>, the latest addition, so that would have to be added)

Quote
i always thought, that gcc does find the *.h.gch only in the same directory where the *.h file resides  :?
how can you tell gcc where to look for the PCH file *.h.gch ?

Actually, GCC looks for a gch file or directory in each include directory just before looking for any #included header. So any header #included only like <this> (never like "this") you can put the .gch file/dir in any directory in the include path, as long as it's searched before the one the actual header is in (or in the same one, obviously).
The reason you can't do this with headers #included like "this" is that in that case the current directory is searched first, so if the header is there, then so should the .gch be.
Before Code::Blocks supported precompiled headers, I actually had an extra directory I put in the path that only contained wx/precomp.h.gch and wx/setup.h (which #defined WX_PRECOMP and then used #include_next to get the actual setup.h).
Title: Re: Precompiled Headers Strategy
Post by: tiwag on November 02, 2005, 07:30:19 PM
thanks to Yiannis and Urxae for all of your explanations, i understand better now !