Sylvestre's blog

libc++: New C++ standard library in Debian

· sylvestre · Développement, Debian, LLVM/Clang · 3 commentaires

Thanks to the work of Andrej Belym, Debian has now a new C++ standard library. This work has been done in the context of the Google Summer of Code 2012.
Available in Debian Experimental, this new packages provides both the runtime libraries (libc++abi1) and the C++ headers (libc++-dev).

With this library, it is possible to build a C++-based program without any dependency on libstdc++.

For example, as detailed in README.Debian, with the (amazing) C++ code:

// foo.cpp
#include <iostream>

int main() {
std::cout < < "plop" << std::endl;
return 0;
}

build with clang++ (or g++) will give:

$ clang++ -o plop foo.cpp
$ ldd plop |grep c++
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f15791cb000)

Using libc++, it will drop the dependency on libstdc++ to use lib++

$ clang++ -stdlib=libc++ -o plop foo.cpp
$ ldd plop |grep c++
libc++.so.1 => /usr/lib/x86_64-linux-gnu/libc++.so.1 (0x00007f87464df000)

For the record, it is not that trivial to do with g++. The command being:

g++ -nostdlib -lc++ -lc++abi -std=c++11 -o plop /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o foo.cpp /usr/lib/x86_64-linux-gnu/crtn.o -isystem/usr/include/c++/v1 -lc -lgcc_s

Besides this change, libc++ provides a support of C++ 11, considered as "correct" against the C++11 standard by upstream.

// bar.cpp
#include <chrono>
int main() {
return 0;
}

clang++ -stdlib=libc++ -o bar bar.cpp

More information:

3 commentaires

Benjamin Kay ·

Congratulations! This is very helpful to those of us developing with C++11 and Clang on Debian!

Julian Andres Klode ·

Nice post, but something is wrong with the planet.debian.org integration or with Google reader, as that leads me to

http://sylvestre.ledru.info/blog/xmlsrv/805@http://sylvestre.ledru.info/blog

(your guid) when trying to open the blog, as reader seems to ignore and only respect elements.

sylvestre ·

@Julien, it works for me ?! (both reader + planet)

Les commentaires sont clos : ce blog est une archive statique.