Installing LLVMs libcxx on linux
libcxx on linux
Currently Clang is shipped using GNUs STL by default, which is basically a C++98 library with some C++11 features added. libc++ is LLVMs C++11 implementation of the C++ Standard Library, which is written for C++11 and thus might provide some benefits for C++11 code. Also there are some license concerns with GNUs STL, however, as of today, you don't really get rid of GNU dependencies it if you use Clang on linux.
While Clang support for libc++ and the library itself is envoling, you still need to compile libc++ and libc++abi on your own. At least i don't know about any distributions which package Clang with libc++ included.
libc++
Installing libc++ is easy. For this article, i ignore packaging as well as any distro-specific concerns, you should easily be able to adjust the steps to your distribution. You need to install Clang first and need to know where Clangs prefix is, i assume /usr
export BASEDIR="$PWD" svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx cd libcxx/lib ./buildit sudo cp libc++.so.1.0 /usr/lib/ sudo cp -R ../include /usr/include/c++/v1 sudo ln -s libc++.so.1.0 /usr/lib/libc++.so sudo ldconfig
libc++abi
libc++abi apperas to be not very well tested on linux, the primary developmentplatform is Mac OS-X. To compile it, you'll need to copy gccs internal unwind.h, that will be found in the libdir of gcc. Also i needed to replace __unwind_word__ with __word__, which might or might not be identically on your platform
cd $BASEDIR svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi cd libcxxabi/include sed 's/__unwind_word__/__word__/g' /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/include/unwind.h > unwind.h cd ../lib ./buildit sudo cp libcxxabi/lib/libc++abi.so.1.0 /usr/lib sudo ln -s libc++abi.so.1.0 /usr/lib/libc++abi.so sudo ldconfig
Testing
Now you can use libc++ it if you add the right paramenters to clang++
clang++ -std=c++11 -stdlib=libc++ -lc++abi -o test test.cpp
Unfortunately the implementation is still incomplete. However, it might be complete enough for you to play arround with some features. If you run the test, you'll see what is working.
cd $BASEDIR/libcxx/test export OPTIONS="-std=c++11 -stdlib=libc++ -lc++abi" ./testit
Most tests are passing allready, however, there are some important features that are not working and of course, there is no evidence, that the tests cover the full featureset of C++11.
Results for libcxx/test: using clang version 3.1 (branches/release_31) Target: x86_64-unknown-linux-gnu Thread model: posix with -std=c++11 -stdlib=libc++ -lc++abi ---------------------------------------------------- sections without tests : 0 sections with failures : 51 sections without failures: 1013 + ---- total number of sections : 1064 ---------------------------------------------------- number of tests failed : 186 number of tests passed : 4153 + ---- total number of tests : 4339 ****************************************************