[cfe-dev] Default Headers with CompilerInstance

Manuel Klimek klimek at google.com
Thu Nov 8 10:22:40 PST 2012


See here for what's needed to build a tool on top of clang:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?revision=166508&view=markup
(the solution is to use the Driver, which handles finding of builtin and
system includes)

Alternatively, you can just use the tooling library :) (see
http://clang.llvm.org/docs/LibTooling.html)

Cheers,
/Manuel


On Wed, Nov 7, 2012 at 11:42 PM, Antoine Trouve <trouve at isit.or.jp> wrote:

> Hello everybody
>
> I am now using clang API in order to alter some C sources using my custom
> ASTVisitor, and I am struggling to make my CompilerInstance object to know
> about the path of default system headers.
>
> I have a protoype that uses the object CompilerInstance to initialize all
> the important stuffs (DiagnosticsEngine, Preprocessor ...) and calls
> "clang::ParseAST" at the end to use my own visitor.
> This prototype works well for simple file that do not use any system
> headers (e.g. "stdlib.h"), but when I want to use these, I get errors like:
>
> $ tsc.c:34:10: fatal error: 'stdlib.h' file not found
> $ #include <stdlib.h>
>
> If I set "Verbose = 1" to the HeaderSearchOptions of my CompilerInstance
> object, I can see that indeed, my search list is empty:
>
> $ #include "..." search starts here:
> $ End of search list.
>
> I tried to add the system headers manually using "HeaderSearchOptions.Add"
> but (1) this is not portable and (2) anyway I can't make that work either.
>
> Could you please explain me more in details how Clang does to find the
> default system headers ?
> I attach the source file of my simple prototype.
>
> Best regards,
>
> - Antoine
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121108/0118c374/attachment.html>


More information about the cfe-dev mailing list