<div style="font-family: arial, helvetica, sans-serif; font-size: 10pt"><br><div class="gmail_extra">On Mon, Nov 12, 2012 at 6:33 PM, Antoine Trouve <span dir="ltr"><<a href="mailto:trouve@isit.or.jp" target="_blank">trouve@isit.or.jp</a>></span> wrote:<br>
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Thank you for you answers:<br>
<br>
@ Jordan<br>
<div class="im">> Is -internal-isystem the flag that controls this? That seems to be what lit is using for %clang_cc1.<br>
</div>Thank you. I looked up into Clang's sources and found many relevant references to this option, right into the Driver.<br>
<br>
@ Manuel<br>
<div class="im">> That is not true :) While not "magic", the way to do this is to use the Driver (which is exactly what clang-the-compiler uses to find the system and builtin includes).<br>
</div>That is right. The implementations of the Driver (and ToolChain) seem to feature some nice features I should use.<br>
<br>
I guess that means I will have forget about any CompilerInstance object. Do you have any code snippet that uses the Driver ?<br>
And by the way, will I still be able to use ASTParser() ?<br></blockquote><div><br></div><div>See:</div><div><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?revision=166508&view=markup" target="_blank" style="font-family:arial,helvetica,sans-serif;font-size:13px">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?revision=166508&view=markup</a></div>
<div>The implementation of the Tooling library uses the drive exactly in the way you'd need to use it - you can either copy that code, or use the Tooling library :)</div><div><br></div><div>Cheers,</div><div>/Manuel</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Regards<br>
<br>
- Antoine<br>
<br>
Le H.24/11/13 à 11:11, Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>> a écrit :<br>
<div class=""><div class="h5"><br>
> On Mon, Nov 12, 2012 at 5:19 PM, Antoine Trouve <<a href="mailto:trouve@isit.or.jp">trouve@isit.or.jp</a>> wrote:<br>
>> Thank you for all your answers and sorry for the late reaction.<br>
>><br>
>> Let we avoid any misunderstanding. I can compile Clang and I can compile my tool without any issue.<br>
>> The issue with systems headers occurs when I execute my tool, and when my tool parses a C file (or preprocesses it, with a "Preprocessor" object).<br>
>><br>
>> If I sum up your answers, there is no "magic" way that would make Clang API know about the path of my system headers.<br>
><br>
> That is true.<br>
><br>
>> I have to "hard-code" them.<br>
><br>
> That is not true :) While not "magic", the way to do this is to use the Driver (which is exactly what clang-the-compiler uses to find the system and builtin includes).<br>
><br>
><br>
>> I find that a bit weird as when I compile Clang from the svn and use it as a frontend for LLVM to compile my files, it finds the headers without any intervention from myself.<br>
>> Moreover, I've noticed that if I use libclang as defined in "Index.h" it also finds these. In this case however, I have to pass an argument to the function "clang_createTranslationUnitFromSourceFile" (at least "-Xclang", even without any further parameters is OK). However I've quitted with using it as seems no to feature any routines to parse the AST node by node, modify it and deserialize it.<br>

>><br>
>> I haven't tried the tooling library yet, does it feature such possibilities ?<br>
>><br>
> Yes. It uses the driver and a compilation database so it gets the exact same flags your normal compile gets, which, combined, will lead to the right headers being found in the right places.<br>
><br>
> Cheers,<br>
> /Manuel<br>
><br>
><br>
> Best regards,<br>
><br>
> - Antoine<br>
><br>
> Le H.24/11/09 à 4:21, Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>> a écrit :<br>
><br>
> > On Thu, Nov 8, 2012 at 10:42 AM, Mehdi AMINI <<a href="mailto:mehdi.amini@silkan.com">mehdi.amini@silkan.com</a>> wrote:<br>
> > Hi,<br>
> ><br>
> ><br>
> ><br>
> > Le 08/11/2012 10:22, Manuel Klimek a écrit :<br>
> ><br>
> > See here for what's needed to build a tool on top of clang:<br>
> > <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?revision=166508&view=markup" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?revision=166508&view=markup</a><br>

> > (the solution is to use the Driver, which handles finding of builtin and<br>
> > system includes)<br>
> ><br>
> > Alternatively, you can just use the tooling library :) (see<br>
> > <a href="http://clang.llvm.org/docs/LibTooling.html" target="_blank">http://clang.llvm.org/docs/LibTooling.html</a>)<br>
> ><br>
> > None of these solutions relieves you from building your binary at the same place at Clang is installed, or duplicate the Clang headers along your tool installation so that they are in PATH_TO_BIN/../lib/...<br>

> > Or did I miss something at some point?<br>
> ><br>
> > What you can do is slurp up the builtin headers as char*'s in your sources, compile them into your binary, and use virtual files at runtime with LibTooling (we're actually doing that for our internal mapreduce framework).<br>

> ><br>
> > The problem with this approach, and the main reason Chandler has opposed doing that for quite some time, is that when you see errors that reference the builtin headers you'll not be able to open those files from your editor (Chandler will jump in if I misrepresented his views :)<br>

> ><br>
> > Cheers,<br>
> > /Manuel<br>
> ><br>
> ><br>
> ><br>
> >     I tried to add the system headers manually using<br>
> >     "HeaderSearchOptions.Add" but (1) this is not portable and (2)<br>
> >     anyway I can't make that work either.<br>
> ><br>
> >     Could you please explain me more in details how Clang does to find<br>
> >     the default system headers ?<br>
> >     I attach the source file of my simple prototype.<br>
> ><br>
> ><br>
> > From my (very shallow) experience, unless you get very deep with the initialization it end up by looking the headers from the place the binary is installed.<br>
> ><br>
> > Best,<br>
> ><br>
> > Mehdi<br>
> ><br>
><br>
><br>
<br>
</div></div></blockquote></div><br></div></div>