[cfe-dev] libclang cannot find its resource dir on linux?
erik.verbruggen at me.com
Thu Jan 9 00:58:26 PST 2014
On 08 Jan 2014, at 14:48, Milian Wolff <mail at milianw.de> wrote:
> On Tuesday 07 January 2014 18:13:16 Sean Silva wrote:
>> This is a known problem for external tools and is a huge pain. The
>> underlying problem is that the resource dir is looked up relative to the
>> current executable. This works fine for clang which is installed in the
>> right place so that this works.
>> The exact path that it looks up relative to the executable can be found in
>> CompilerInvocation::GetResourcesPath in lib/Frontend/CompilerInvocation.cpp
>> Here are 3 ways to work around this:
>> 1. Put your executable in the same place as the clang binary.
>> 2. Copy/symlink the resource dir to the same relative location from your
>> executable as they are from the clang binary.
>> 3. Pass the argument `-resource-dir /path/to/resource/dir`. It is a `clang
>> -cc1` argument so you need to use the `-Xclang` prefix to pass it, i.e.
>> `-Xclang -resource-dir -Xclang /path/to/resource/dir`.
> There is a fourth one, which I came up with as a good-enough workaround:
> Ask clang for the include paths, i.e.:
> clang -xc++ -E -v /dev/null
> That gives you a list of built-in search paths, including in my case:
> So you can parse the above command once, then pass these paths via -I to
> The advantage I see here is that you don't have to know the resource dir in
> advance, but can simply ask clang for it.
Well, the whole reason for that code snippet was to ask libclang for its resource path, so I can pass it around. Asking the clang executable means that linux users need to have that installed, while they might not use it at all.
And the reason for passing around the resource path, is because of problems with libstdc++4.8 that comes with the gcc toolchain, and its use of intrinsics. See my other post for that.
More information about the cfe-dev