1

I believe this issue is related to Broken c++ std libraries on macOS High Sierra 10.13, however, the fixes there did not help -- so this could be a different type of issue.


The issue

This is the code I am using to test compile; I can reproduce the issue with any C++ file, however.

#include <iostream>
#include <iterator>
#include <algorithm>
int main() {
     std::copy(std::istream_iterator<char>{std::cin}, {}, std::ostream_iterator<char>{std::cout, ""});
    return 0;
}

This produces this error:

clang++ -std=c++11 test.cpp
In file included from test.cpp:1:
In file included from /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iostream:38:
In file included from /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ios:216:
In file included from /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__locale:15:
In file included from /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:470:
In file included from /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string_view:169:
In file included from /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__string:56:
In file included from /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:643:
In file included from /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:650:
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iterator:432:10: fatal error: 'Availability.h' file not found
#include <Availability.h>
         ^~~~~~~~~~~~~~~~

Now, I'm not sure why that header would be missing. Either way, I downloaded old versions of the headers off the internet, and tried that. This actually compiled my test file, but lead to errors in other files, leading me to believe that my toolchain was broken. I then completely reinstalled both the stable and beta versions of Xcode, got the exact same issue.

The other error I get is this:

/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/math.h:1272:93: error: no member named 'llrintf' in the global namespace
 inline _LIBCPP_INLINE_VISIBILITY long long llrint(float __lcpp_x) _NOEXCEPT       {return ::llrintf(__lcpp_x);}

Which I have noticed to be exactly the same as this ancient one https://gist.github.com/pjmartorell/4165805. That gist does not have a fix.


Steps I've tried

  • Switching to the stable toolchain
  • Reinstalling Xcode
  • Rebooting
  • Downloading the missing headers manually
  • xcode-select --install

This is my first issue on SO, apologies if this is in the wrong place, or if I haven't gone into enough detail. This is just driving me insane at this point.

  • Could the problem be that you had at one point downloaded a beta of Xcode and you're running it instead of the release version of Xcode? – Louis Langholtz May 13 '18 at 13:54
  • I am purposely using the beta toolchain, but as mentioned, it produces the same results using normal Xcode when switched using Xcode-select. – Jamie Bishop May 13 '18 at 13:57

1 Answers1

0

It appears to me that somehow you got a partial install, where the libc++ headers are fine, but the rest of the headers are not :-(

On my machine (no Xcode any more), I have two copies of that file: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/Availability.h /usr/include/Availability.h

You might want to run clang++ -v <your source file> which will tell you where it's looking.

When I do that, I get:

$ clang -v junk.cpp
Apple LLVM version 9.1.0 (clang-902.0.39.1)
Target: x86_64-apple-darwin17.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
 "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.13.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name junk.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 351.8 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/9.1.0 -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/marshall -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.13.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/r9/6nps4qvj3zlcwhs52mfb0yg00000gn/T/junk-c5a5d1.o -x c++ junk.cpp
clang -cc1 version 9.1.0 (clang-902.0.39.1) default target x86_64-apple-darwin17.5.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
 /Library/Developer/CommandLineTools/usr/include/c++/v1
 /usr/local/include
 /Library/Developer/CommandLineTools/usr/lib/clang/9.1.0/include
 /Library/Developer/CommandLineTools/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.

and try to figure out what you're missing from that.

Marshall Clow
  • 15,972
  • 2
  • 29
  • 45