XCode 9 - new LLVM headers causing errors

My application was compiling fine on XCode 8.3, but does not compile on XCode 9. The error I am getting is "declaration conflicts with target of using declaration already in scope" related to the following header file /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/math.h:719:46: note: target of using declaration.


What I have finally narrowed it down to is XCode 8.3 did not have math.h at the above location. The math.h in this location has LLVM information in the header. In 8.3 it is finding math.h here: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/math.h, which has Apple copywrite information. The two header files are very different. XCode 9 has headers in both locations with the Apple one being in MacOSX10.13.sdk/usr/include/math.h.


I am specifying -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk which should set the system include path. However looking at opensnoop on both 8.3 and 9.0 it is always looking for math.h in the Toolchains (/Applications/Xcode.app/Contents/Developer/Toolchains/...) directory first. I have read the documentation on the include search path and still am not clear what is giving the Toolchains directory priority.


So now for my question:

Should the toolchains directory have priority over the system include path? If not, how can I fix it?


Thank you,

Kris Berg

Replies

Hi,


I definitely agree. I was able to demonstrate that the combination of custom "isysroot" (say iPhoneOS11.sdk) + "isystem" can somehow lead llwm to bypass the provided sysroot, and to use the default toolchain sysroot !


Below is a minimal way of reproducing the error:


Create a file hello.cpp with the following content:

#include <cmath> // end of file !


Create a compile.sh file with the following content:

IPHONESDK=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk

#echo "This will work (with isysroot)"
clang -arch arm64 -isysroot $IPHONESDK -c hello.cpp -o hello.o

echo "This will not work (the failure happens if you combine isysroot & isystem)"
clang -arch arm64 -isysroot $IPHONESDK -isystem $IPHONESDK/usr/include -c hello.cpp -o hello.o


The compilation error output is :

In file included from hello.cpp:1:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath:313:9: error: no
      member named 'signbit' in the global namespace

As you can see in the error output, "cmath" is included from the default development toolchain ("XcodeDefault.xctoolchain"), whereas it should be included from the iPhoneSdk !

Namely, the cmath header should have been :
$IPHONESDK/usr/include/c++/4.2.1/cmath
instead of
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath
This is strange...
Hope this helps, and hoping that it will be solved quickly.

Please tell us if you found a fix for this.

Hi,


The only workaround I have found is to remove "-isystem $IPHONESDK/usr/include" from the compilation command line.

This seems to be still the case with XCode Version 9.2 (9C40b). I am using g++.

I spent few days debuging complex library compilation due to this weird behaviour of LLVM.


Your reply was very helpful. Hope this get the attention it needs.