[cfe-dev] PCH: separation from source header

Argyrios Kyrtzidis kyrtzidis at apple.com
Sun Sep 19 04:29:55 PDT 2010


On Sep 18, 2010, at 6:20 PM, Ilya Murav'jov wrote:

> 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).

This happens because the driver doesn't look into the include directories (-Ibuild) for a PCH file, at your example it will only look into the current directory.
Daniel, should the driver look into the include dirs ?

> 
> 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.

It should, can you post a test case where this doesn't work ?

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

$ clang -c -Isrc -include build/test.h -o build/test.o src/test.c

-Argiris

> 
> 3) What is the reason against using .h.pch automatically like gcc does it?
> 
> Thanks in advance,
> Ilya
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev





More information about the cfe-dev mailing list