can i use the c++20 library with xcode 12? (xcode 12 beta 5, with clang version 10.0.0).
so in xcode build settings, instead of
// in xcode build settings, "c++ standard library"
CLANG_CXX_LIBRARY = libc++
maybe use something like (does not work => clang err: invalid library name)
CLANG_CXX_LIBRARY = libc++20 // eg. libc++20 & libc++2a are invalid names
i have already set (works by providing c++20 language support, but does not provide c++20 library support)
// in xcode build settings, "c++ language dialect"
CLANG_CXX_LANGUAGE_STANDARD = c++2a // ok but does not provide c++20 library
im aware that the c++20 library is not yet complete/officially released.
question:
do you know of any (easy) way to use the (preliminary) c++20 library with xcode 12?
thanks
There can be easier ways, or I might have done something redundant (let me know what can be removed), but here's a surefire way.
If you download the LLVM binaries from LLVM releases, do Step 1 - a and not Step 1 - b.
Download the LLVM + Clang binaries of your choice.
Copy the toolchain from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
and paste it in ~/Library/Developer/Toolchains
.
Right click -> Show package Contents.
ToolchainInfo.plist
file to what you want "MyAmazingToolchain".Move on to Step 2.
Build llvm with
cmake -G "Sublime Text 2 - Ninja" -DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS=“clang;libcxx;libcxxabi” -DCMAKE_CXX_STANDARD=17 -DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_CCACHE_BUILD=ON -DLLVM_CREATE_XCODE_TOOLCHAIN=ON \
-DCMAKE_INSTALL_PREFIX="easy to clean location"\
-DLLVM_ENABLE_RTTI=OFF \
../llvm
libcxxabi
is required or linking libcxx
will fail with:
ld: library not found for -lcxxabi_shared clang: error: linker command failed with exit code 1 (use -v to see invocation)
DLLVM_CCACHE_BUILD
requires https://ccache.dev (use brew if you wish). First build will be very slow. Rebuilds will be faster.
After the above is done and ninja compiles around 3000 files, run
ninja install all
ninja install-xcode-toolchain
Find the created toolchain in location you chose above/Toolchains
. Copy it to ~/Library/Developer/Toolchains/
If Xcode is open, close it and reopen. In Xcode app menu > Toolchains > choose the new one, llvm12git.
Create a new c++ project normally and go to its project's build settings.
Search for COMPILER_INDEX_STORE_ENABLE
or Enable index-while-building functionality
and set it to "No". Otherwise, build fails with "unrecognised option" about indexing.
Change "C++ language dialect" to "c++20" or "c++2a"
Build the project normally. However, warnings may not go away while the code successfully builds due to indexing disabled. :( Adding header search path helps with warnings.
Make sure to check feature status:
Code I tested:
#include <compare>
#include <concepts>
struct Aggr {
int i;
char c;
auto operator<=>(Aggr const &) const = default;
};
struct A {
int x;
int y;
int z;
};
int main()
{
// A a{.y = 2,.x = 1}; // error; designator order does not match declaration
// order
A b{.x = 1, .z = 2}; // ok, b.y initialized to 0
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With