[cfe-dev] PCH: separation from source header

Ilya Murav'jov muravev at yandex.ru
Tue Sep 21 17:56:54 PDT 2010


Argyrios Kyrtzidis пишет:
> On Sep 18, 2010, at 6:20 PM, Ilya Murav'jov wrote:
>
>> 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?
>>

Ok, with Clang 2.9 I succeeded in building my project with PCH, thanks.
I have 2 things to say.

1. I have to say that "-include" scheme is not so flexible as using PCH
automatically, really. Here is my use case: let's say I have a project
(a bunch of sources), and I want to use one PCH-file for it (and so on,
one PCH-file per project). So I set that "-include" option for the
project and now it is used for every source file in the project, without
an exception,- that is no so good! In several cases I do want to avoid it:
- my projects have C++ and C sources together; I can't use C++ PCH
  header for C sources (so the hack is done - "-include" goes to CXX
  options, not CPP ones).
- in some C++ sources I still need to set #defines at first lines (e.g.
BOOST_AUTO_TEST_MAIN for Boost.Test library); now it is impossible.

That said, I need to create additional projects (without PCH) just for
such exceptional sources to make things to work.

2. I have got some benchmarks (compiler' speed in debug mode) gcc vs
clang for my sources (http://gitorious.org/bombono-dvd). I use Boost *a
little*, and it makes a compiler be somewhat slow. Here are compilation
times (-g -O0) for src/mgui/editor/select.cpp (39kb, not so big!):

a) without PCH:
 clang++ 2.9: 5.35 seconds
 g++     4.2: 5.05 seconds

b) with PCH:
 clang++ 2.9: 3.47 seconds
 g++     4.2: 2.88 seconds

So I am sure clang has some room for optimizing like
http://clang.llvm.org/features.html#performance states it. :)

Regards,
 Ilya

P.S. Anyway, I was surprised when clang managed to build all my projects
and all tests are working! (except just a trivial one -
http://llvm.org/bugs/show_bug.cgi?id=8182).



More information about the cfe-dev mailing list