[cfe-dev] libclang cannot find its resource dir on linux?
mail at milianw.de
Wed Jan 8 05:48:34 PST 2014
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.
> 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;
> > unsaved.Filename = "tst.c";
> > unsaved.Contents = "#include <xmmintrin.h>\n";
> > unsaved.Length = strlen(unsaved.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
mail at milianw.de
More information about the cfe-dev