We are writing server-side C++ code that runs on Linux in production but some of the developers use Macs. We standardized on Clang 14 (or the equivalent Apple Clang) and libc++ as the runtime library. The dev environment is either VSCode or CLion.
I have clang 14 installed via Xcode, and even though it also installed libc++ 14, it chooses to use libc++ 13 instead (from a different directory).
% printf "#include <version>\nint main(){}" | /usr/bin/clang++ -std=c++20 -stdlib=libc++ -E -x c++ -dM - | grep _LIBCPP_VERSION
#define _LIBCPP_VERSION 13000
Some investigation (grep output trimmed:
% grep -R -H "#define _LIBCPP_VERSION" --include=__config --exclude-dir=System / 2>/dev/null
/Library/Developer/CommandLineTools/usr/include/c++/v1/__config:#define _LIBCPP_VERSION 14000
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__config:#define _LIBCPP_VERSION 13000
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__config:#define _LIBCPP_VERSION 14000
So 14.0 is installed, but the directory with 13.0 is selected:
% printf "#include <__config>\nint main(){}" | /usr/bin/clang++ -std=c++20 -stdlib=libc++ -E -x c++ - | grep "2 3"
# 14 "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/__config" 2 3
Let's see what else clang has to say:
% /usr/bin/clang++ -v
Apple clang version 14.0.0 (clang-1400.0.29.102)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
% clang++ -print-search-dirs
programs: =/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
libraries: =/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.0
So for some reason, clang takes the libraries from one directory, but the standard headers from another.
I could try using -nostdlibinc and specifying the "correct" include directory explicitly, but I am not sure what the side effects will be and I'd rather understand what's going on.