Closed Quuxplusone closed 3 years ago
Attached 02.log
(63983 bytes, text/plain): Full build log
This error occurs because you are compiling a C++ program, and are using "-
isystem
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include",
which puts this directory at the front of your include search dirs, *before*
the libc++ include directory.
This will not work correctly, and you should probably just stop adding -
isystem. But if that is not possible for other reasons, you should also add the
libc++ include directory *before* the regular include directory, i.e. do
something like:
-isystem ${SDKDIR}/usr/include/c++/v1 -isystem ${SDKDIR}/usr/include
(Assuming here that
SDKDIR="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk")
How this happens is as follows. By default, if you compile a C++ program, clang
sets up the include search dirs similar to:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.0.0/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
Any header such as <cmath> or <math.h> will therefore be found *first* in the
libc++ include directory, ${SDKDIR}/usr/include/c++/v1. Whenever libc++ wants
to use the C version of <math.h>, it will include it using
#include_next<math.h>, which attempts to find math.h from the *next* path in
the search directory list.
So normally, including <cmath> goes like:
* #include <cmath> -> finds ${SDKDIR}/usr/include/c++/v1/cmath
* #include <math.h> -> finds ${SDKDIR}/usr/include/c++/v1/math.h (this is
a wrapper header)
* #include_next <math.h> -> finds ${SDKDIR}/usr/include/math.h
Now if you add -isystem ${SDKDIR}/usr/include to your compilation, the include
search dirs will look like:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
I.e., ${SDKDIR}/usr/include is now before ${SDKDIR}/usr/include/c++/v1, and
then including <cmath> goes like:
* #include <cmath> -> still finds ${SDKDIR}/usr/include/c++/v1/cmath, as
before
* #include <math.h> -> finds ${SDKDIR}/usr/include/math.h, the plain C one
and *not* the wrapper header
* there won't be any #include_next <math.h> now since the plain C version does
not do that
* back in <cmath>, several "using" directives will now fail since the libc++
math.h wrapper was not included first
So the conclusion of this story is: if you really must set your own system
include paths using -isystem, that is fine, but you *must* also set the C++
include paths correctly, and in the right order, not only the plain C include
paths.
Thank you for the detailed info Dimitry; that all makes total sense! I'll check the Rust build system to see if I can find out where these flags are being set and try to submit a patch downstream :)
(In reply to Chris Long from comment #2)
> Thank you for the detailed info Dimitry; that all makes total sense! I'll
> check the Rust build system to see if I can find out where these flags are
> being set and try to submit a patch downstream :)
Note that in FreeBSD we've also encountered this issue with a number of ports,
which were setting their own -isystem flags incorrectly. E.g. this is not
limited to macOS. :)
02.log
(63983 bytes, text/plain)