"libc++" C++ Standard Library

libc++ is a new implementation of the C++ standard library, targeting C++11.

All of the code in libc++ is dual licensed under the MIT license and the UIUC License (a BSD-like license).

Features and Goals

Why a new C++ Standard Library for C++11?

After its initial introduction, many people have asked "why start a new library instead of contributing to an existing library?" (like Apache's libstdcxx, GNU's libstdc++, STLport, etc). There are many contributing reasons, but some of the major ones are:

Platform Support

libc++ is known to work on the following platforms, using g++-4.2 and clang (lack of C++11 language support disables some functionality).

Current Status

libc++ is a 100% complete C++11 implementation on Apple's OS X.

LLVM and Clang can self host in C++ and C++11 mode with libc++ on Linux.

C++1Y (C++14) implementation is in progress. The current status is here

Ports to other platforms are underway. Here are recent test results for Windows and Linux.

Get it and get involved!

First please review our Developer's Policy.

To check out the code, use:

On Mac OS 10.7 (Lion) and later, the easiest way to get this library is to install Xcode 4.2 or later. However if you want to install tip-of-trunk from here (getting the bleeding edge), read on. However, be warned that Mac OS 10.7 will not boot without a valid copy of libc++.1.dylib in /usr/lib.

Next:

That should result in a libc++.1.dylib and libc++.dylib. The safest thing to do is to use it from where your libcxx is installed instead of replacing these in your Mac OS.

To use your system-installed libc++ with clang you can:

To use your tip-of-trunk libc++ on Mac OS with clang you can:

To run the libc++ test suite (recommended):

Notes

Building libc++ with -fno-rtti is not supported. However linking against it with -fno-rtti is supported.

Send discussions to the (clang mailing list).

Build on Linux using CMake and libsupc++.

You will need libstdc++ in order to provide libsupc++.

Figure out where the libsupc++ headers are on your system. On Ubuntu this is /usr/include/c++/<version> and /usr/include/c++/<version>/<target-triple>

You can also figure this out by running

$ echo | g++ -Wp,-v -x c++ - -fsyntax-only
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.7
 /usr/include/c++/4.7/x86_64-linux-gnu
 /usr/include/c++/4.7/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.7/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
     
Note the first two entries happen to be what we are looking for. This may not be correct on other platforms.

We can now run CMake:

You can now run clang with -stdlib=libc++.

Build on Linux using CMake and libc++abi.

You will need to keep the source tree of libc++abi available on your build machine and your copy of the libc++abi shared library must be placed where your linker will find it.

We can now run CMake:

Unfortunately you can't simply run clang with "-stdlib=libc++" at this point, as clang is set up to link for libc++ linked to libsupc++. To get around this you'll have to set up your linker yourself (or patch clang). For example,

Alternately, you could just add libc++abi to your libraries list, which in most situations will give the same result:

Build on Linux using CMake and libcxxrt.

You will need to keep the source tree of libcxxrt available on your build machine and your copy of the libcxxrt shared library must be placed where your linker will find it.

We can now run CMake:

Unfortunately you can't simply run clang with "-stdlib=libc++" at this point, as clang is set up to link for libc++ linked to libsupc++. To get around this you'll have to set up your linker yourself (or patch clang). For example,

Alternately, you could just add libcxxrt to your libraries list, which in most situations will give the same result:

Design Documents