[cfe-dev] PCH: separation from source header

Ilya Murav'jov muravev at yandex.ru
Sat Sep 18 10:20:15 PDT 2010


Hi,

 I am trying to adapt Clang' PCH to my build system from example here,
http://clang.llvm.org/docs/UsersManual.html#precompiledheaders . Here is
the test case:

$ ls -R
.:
build  src

./build:
test.h.pch

./src:
test.c  test.h

$ cat test.c
#include <test.h>

$ clang -x c-header -Ibuild -Isrc -o build/test.h.pch src/test.h
$ clang -c -Ibuild -Isrc -include test.h -o build/test.o src/test.c

It seems that clang fails to use build/test.h.pch in such situations (I
checked that for some non-trivial C++ sources - no performance gain).

So, here is the questions:
1) How can I make sure that PCH header is being used, not test.h? For
gcc, I use special "fake" build/test.h with contents like so:
#error PCH' using is failed, that shouldn't be done :(

then, if PCH cannot be used than compilation will break. But this is not
working for clang.

2) Is it possible to use Clang' PCH in the test case above? If not then
what is a solution?

3) What is the reason against using .h.pch automatically like gcc does it?

Thanks in advance,
 Ilya



More information about the cfe-dev mailing list