[cfe-dev] Extracting the include tree from a source file

Bertjan Broeksema broeksema at kde.org
Mon Nov 15 11:33:51 PST 2010


Hi,

Nico Weber wrote:

Thanks for the quick reply!

> Hi,
> 
> Call InitializePreprocessor to add defines. To fix the crash, add
> calls to BeginSourceFile()/EndSourceFile() (see
> https://github.com/nico/clangtut/blob/master/tut03_pp.cpp ).

Yes, I'm a step closer now, it indeed doesn't crash anymore when an error 
occurs. However, I still have the problem that system includes are not 
found. In this particular case stddef.h. I am somewhat assuming that it 
shouldn't be needed to add paths like:

/usr/include/linux (for stddef.h)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.4/include

clang++ (the command line tool), seems to have these paths available as it 
is able to preprocess the same file I'm testing with, without complaining 
about not finding stddef.h

> Take a look at include/clang/Lex/PPCallbacks.h – you probably want to
> derive a class from that and set it on the preprocessor to be notified
> of includes and defines in the code.

Will do, thanks for the pointer.

Bertjan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 2972 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20101115/5377dcc1/attachment.cpp>


More information about the cfe-dev mailing list