[cfe-dev] Errors in local system headers when using clang libTooling tool

Steven Wu via cfe-dev cfe-dev at lists.llvm.org
Thu May 3 17:54:51 PDT 2018


Hi Eberhard

The compiler headers (the ones in */usr/lib/clang/*/include) are rev-locked with the compiler. You cannot mismatch between different versions.

On the other hand, as long as you are not using compiler builtin functions, you can switch to use the compiler headers from clang 6.0 instead of the ones come with your local toolchain. That should solve your problem.

Steven

> On May 3, 2018, at 11:49 AM, Eberhard Gräther via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> Hello cfe-dev,
> 
> I’m using clang libTooling for creating a GUI developer tool, currently with clang 6.0. The tool makes use of the local system headers when analyzing source code. From my local compiler I get these system header paths:
> 
>     $ clang++ -x c++ -v -E /dev/null
>     ...
>     #include <...> search starts here:
>      /usr/local/include
>      /opt/local/include
>      /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
>      /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.1.0/include
>      /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
>      /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include
>      /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks (framework directory)
>> 
> 
> My local toolchain is based on Xcode:
> 
>     $ clang++ -v
>     clang version 5.0.1 (http://llvm.org/git/clang.git 232230afd349ceeb784720d2266e2288523d871f) (http://llvm.org/git/llvm.git cbc2c76b286c38a1fd006543b6b224c06cd96df1)
>     Target: x86_64-apple-darwin17.5.0
>     Thread model: posix
>     InstalledDir: /usr/local/bin
> 
> 
> My tool usually works fine, and most source code can be analysed without problems. But sometimes there are errors like this one:
> 
>     /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.1.0/include/emmintrin.h:2261:19: fatal error: use of undeclared identifier '__builtin_ia32_pavgb128'
>       return (__m128i)__builtin_ia32_pavgb128((__v16qi)__a, (__v16qi)__b);
>                       ^
>     error: use of undeclared identifier ‘__builtin_ia32_pavgb128'
> 
> 
> I found out that this problem might be related to the preprocessor definitions of my tool. My tool either uses the wrong ones or misses some. I can get a list from my local compiler and make my tool use them:
> 
>     $ clang++ -x c++ -E -dM /dev/null
>     #define OBJC_NEW_PROPERTIES 1
>     #define _LP64 1
>     #define __APPLE_CC__ 6000
>     #define __APPLE__ 1
>     #define __ATOMIC_ACQUIRE 2
>     #define __ATOMIC_ACQ_REL 4
>     #define __ATOMIC_CONSUME 1
>     #define __ATOMIC_RELAXED 0
>     #define __ATOMIC_RELEASE 3
>> 
> 
> But that just switches the problem to some other location:
> 
>     /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/stdlib.h:162:54: fatal error: redefinition of parameter 'restrict'
>     size_t   mbstowcs(wchar_t * __restrict , const char * __restrict, size_t);
>                                                           ^
>     /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/sys/cdefs.h:209:20: note: expanded from macro '__restrict'
>     #define __restrict      restrict
>                             ^
>     error: redefinition of parameter ‘restrict’
> 
> 
> I couldn’t find a good resource explaining me this situation yet. What am I doing wrong here?
> Is this a problem of wrong/missing preprocessor definitions?
> Or does my clang 6.0 tool not match with my local clang 5.0.1 toolchain’s system headers?
> Do I need to ship certain system headers with my tool?
> 
> Thank you,
> Eberhard Gräther
> 
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list