How to setup a basic program using clang libs?

Hi all,

I'm trying to get known with using the clang libraries but I'm somewhat
stuck. First of all most documentation (in particular tutorials) seem
outdated, any pointers would be appreciated.

Currently I've a simple program which does nothing more than setting up the
preprocessor but it doesn't find standard include headers it seems. Probably
I'm missing something trivial but I currently don't see what. Any help would
be appreciated.

For the context, I'm trying to write a little program that prints out the
include tree of a source file.

Cheers,

Bertjan

includetreeprinter.cpp (4.08 KB)

The system headers thing is a major gotcha that really frustrated me when I was first starting to program with clang. The reality is that the work of setting up the default system headers is done by the Driver (or Frontend, I forget which). Those parts of clang are separate from the Preprocessor, so there is just no simple way to have it “just work” :frowning:

The “usual” way to work around this is to run as a clang plugin. There are docs about that at http://clang.llvm.org/docs/ClangPlugins.html

best of luck,
–Sean Silva

The system headers thing is a major gotcha that really frustrated me when I was first starting to program with clang. The reality is that the work of setting up the default system headers is done by the Driver (or Frontend, I forget which). Those parts of clang are separate from the Preprocessor, so there is just no simple way to have it “just work” :frowning:

The “usual” way to work around this is to run as a clang plugin. There are docs about that at http://clang.llvm.org/docs/ClangPlugins.html

Depending on what your goals are, libclang or libtooling might also fit your use case.
Start at:
http://clang.llvm.org/docs/Tooling.html
with a comparison of the approaches (I don’t know whether libclang supports preprocessor interception; if not, libtooling and clang plugins are your options).

Cheers,
/Manuel