[cfe-dev] libclang cannot find its resource dir on linux?

Sean Silva silvas at purdue.edu
Tue Jan 7 17:13:16 PST 2014

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`.

-- Sean Silva

On Tue, Jan 7, 2014 at 7:59 AM, Erik Verbruggen <erik.verbruggen at me.com>wrote:

> Hi,
> I have a small test program that behaves differently on linux and mac:
>      CXIndex idx = clang_createIndex(1, 1);
>     struct CXUnsavedFile unsaved[1];
>     unsaved[0].Filename = "tst.c";
>     unsaved[0].Contents = "#include <xmmintrin.h>\n";
>     unsaved[0].Length = strlen(unsaved[0].Contents);
>     CXTranslationUnit tu = clang_parseTranslationUnit(idx, "tst.c", 0, 0,
> unsaved, 1, 0);
> On macos, the translation unit is fine: when running clang_getInclusions
> on it, I get the full path of xmmintrin.h. However, on linux this fails
> with "tst.c:1:10: fatal error: 'xmmintrin.h' file not found". Running it on
> the command-line works fine though.
> So, is this expected behaviour, or a bug?
> -- Erik.
> _______________________________________________
> 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/20140107/35f71b47/attachment.html>

More information about the cfe-dev mailing list