File: README.PCH

package info (click to toggle)
libcwd 1.0.3-1
  • links: PTS
  • area: non-free
  • in suites: squeeze
  • size: 8,104 kB
  • ctags: 10,429
  • sloc: cpp: 23,337; sh: 9,798; ansic: 1,172; makefile: 848; exp: 234; awk: 11
file content (50 lines) | stat: -rw-r--r-- 1,951 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
A warning for those who want to use PCH (pre compiled headers):
g++ does NOT take the "current directory" from which the
compiler was started into account.  This means that if you use
a PCH that includes a header file (such as #include "debug.h",
or "sys.h"!) which might change depending on the directory
you are in, then g++ might re-use an old PCH while it shouldn't.
The most likely result of this is a half-way change of the macro
DEBUGCHANNELS and therefore an 'unknown' debug channel that you
DID declare.

In order to avoid this, you should, for every project, put the
PCH in the same directory as the projects debug.h/sys.h (assuming
your PCH includes debug.h of course, as is a logical thing to do)
and put the search path for the PCH/debug.h directory always up
front.

For example, if you would make a common directory with a PCH
file and have it contain something like:

#include "sys.h"
#include "debug.h"
#include <iostream>
#include <string>

because you always use those in all your projects anyway, then
this will not work - without any warnings.  The reason being
that "sys.h" and "debug.h" are *different* files for every
project.  You cannot use a common PCH therefore, and g++ will
not see this.

Another example of how this can go wrong is as follows:

project/include/pch.h	// Includes debug.h
project/include/debug.h

And then another project trying to use the previous project
before it is installed (or after it is installed if you
also install the pch.h.chg; don't do that).

otherproject/include/debug.h	// Other debug.h

Now if you forget to create pch.h there, but you pass the
same compiler commandline parameters to compile this project,
including the "-include pch.h" then that might cause the
wrong debug.h to be included (via the existing pch.h.cgh
in project/include) even while the normal search path for
"debug.h" would get the one in otherproject/include.

In other words, you need to know what you are doing.