[cfe-dev] argv[0] in libclang

Manuel Klimek via cfe-dev cfe-dev at lists.llvm.org
Tue Oct 20 06:58:21 PDT 2015


+argyrios and richard for more opinions

On Thu, Oct 15, 2015 at 11:04 AM Manuel Klimek <klimek at google.com> wrote:

> On Thu, Oct 15, 2015 at 11:02 AM Milian Wolff via cfe-dev <
> cfe-dev at lists.llvm.org> wrote:
>
>> On Thursday, October 15, 2015 10:30:54 AM CEST Benjamin Kramer via cfe-dev
>> wrote:
>> > Hi,
>> >
>> > currently all libclang APIs that get passed a command line expect that
>> > there is no argv[0] in the list, i. e. no binary name at the beginning
>> > of the command line. We later fake one
>> > (clang::createInvocationFromCommandLine) as the invocation gets passed
>> > down into the proper clang machinery.
>> >
>> > This is nasty because it changes the behavior if the original clang
>> > invocation would've used a relative path to the standard library:
>> >
>> > cmdline: /foo/bar/bin/clang -c test.cc
>> > std lib in: /foo/bar/include/c++
>> > libclang sees: -c test.cc
>> >
>> > and the stdlib is lost. This comes up if we're using a compile
>> > database, for example ycm is using it like this.
>> >
>> > The only sane solution I see at the moment is to add a new libclang
>> > API that expects a full argv. Any other ideas?
>>
>> In KDevelop, we parse the output of
>>
>>         clang++ --std=c++11 -xc++ -E -v /dev/null
>>
>> and pass those in to liblcang as explicit include paths. It works fine
>> for our
>> use case.
>
>
> Note that this might also be wrong.
> If you have multiple compilers / libstdc++'s installed, it is important to
> take the right one for the current project you work in.
>
>
>> But for a simpler tool it might be far too much overhead of course
>> to get up and running. Couldn't the code path in clang use the path to the
>> clang library as a fallback when no binary is given? That way, nothing
>> needs
>> to be changed.
>>
>> Bye
>> --
>> Milian Wolff
>> mail at milianw.de
>> http://milianw.de
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151020/daa05435/attachment.html>


More information about the cfe-dev mailing list