<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 19, 2013 at 7:52 PM, Val Markovic <span dir="ltr"><<a href="mailto:val@markovic.io" target="_blank">val@markovic.io</a>></span> wrote:<br>
<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"><div style="font-family:arial,sans-serif;font-size:13px">From what I can gather, it appears that when compiling a C++ file with the clang binary, clang will use some default header search paths. But when trying to do the same from libclang, it won't. Is this caused by the clang driver/frontend distinction (I don't know much about it)?<br>
</div></blockquote><div><br></div><div>Yes, the Clang driver handles inspection of the host machine to determine the appropriate set of header search, linker search, and other options to use when compiling code.</div><div>
<br></div><div>I suspect that libclang doesn't do this almost entirely for historical reasons. I think that the correct approach would be for libclang to include the Clang driver library in its code and use it when forming "invocations" from commandline flags where those flags are expected to be GCC-compatible commandline flags for compilation.</div>
<div><br></div><div>Specifically, I think the implementation of clang_parseTranslationUnit and clang_indexSourceFile (and any other entry points that accept a "command line") should be implemented in terms of the Clang driver library.</div>
<div><br></div><div>The reason why this hasn't happened yet is (I suspect) because historically many users were on systems and working with build systems where the internal CC1-layer options which those routines support were simple and sufficient to encode into the build system. However, that isn't the right design at all.</div>
<div><br></div><div>Unfortunately, this will be a fairly significant amount of work. I suspect the C++ interfaces in the Driver library are not the correct C++ interfaces to make it easy to support both commandline usage and libclang usage. It'll probably need refactoring at that level in addition to wiring it up to libclang. More unfortunately, in order to not break the existing users we should leave the entrypoints I mentioned in libclang functioning exactly as they are but document that they accept the internal Clang CC1 commandline interface, discourage the use of them, and point at entry points that do the driver-based interpretation of commandline flags.</div>
<div><br></div><div>----</div><div><br></div><div>This is also the correct solution to the thread Sean Silva mentioned. It also would solve a pile of other problems with libclang usage. It also would make it much more feasible for IDE and other things to use a libclang-style C interface for in-process code generation for C++ code. The list goes on.</div>
<div><br></div><div>I don't know of anyone currently working on this though. =[</div><div><br></div><div>-Chandler</div></div></div></div>