clang libc++ libcxxabi std::thread std::async

I am curious if anyone has been able to get clang++ to run std::async in linux at all. If so the process would be great. I have tried TOT + libc++, with stdc++ and also the recently released binaries. In no configuration can I get this to work. As recently reported (not by me) in another mail (lost now), the following fails :

#include

void f(){}

int main() {
std::thread t(f);
t.join();
}

compiled with

clang++ -std=c++11 thread.cc -o thread -pthread

output

./thread
pure virtual method called
terminate called without an active exception
Aborted (core dumped)

using

clang++ --version
clang version 3.1 (tags/RELEASE_31/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix

std::async seems to fail at runtime, I think this is due to abi issues but cannot be sure.

Best Regards
David Irvine

I can't speak for Linux, but I just tried your example on FreeBSD 9-STABLE with the default configuration of clang++, libc++ and libcxxrt that ship as part of the base system and it worked correctly with the following compile command:

$ clang++ -std=c++11 thread.cc -o thread -pthread -stdlib=libc++

David

WorksForMe, but I had to modify your command line to link with libc++abi (as per your subject). My versions of libc++ and libc++abi is ToT (157626) (is there a branch for libc++ and libc++abi for 3.1?)

$ clang++ -v
Debian clang version 3.1-3eudoxos1 (branches/release_31) (based on LLVM 3.1)
Target: x86_64-pc-linux-gnu
Thread model: posix
$ clang++ -std=c++11 -stdlib=libc++ thread_join.cpp -o thread -pthread -lc++abi
$ ./thread
$

Ben

$ ~/Downloads/clang+llvm-3.1-x86_64-linux-ubuntu_12.04/bin/clang++ -v
clang version 3.1 (tags/RELEASE_31/final)

To avoid confusion, I just tried with this version too and it also works.

Ben

Yes, it’s almost enough for me to get to FreeBSD, particularly as I really like the bsd licence, sad as that may seem :-). I think 10 will be switched over completely to clang/libc++. I see libcxxab now reports to have nearly everything done for linux, but I cannot see how it’s built at all, I hoped it would build with libc++ as part of cmake, but alas !!

I think FreeBSD has libc++ set up as some filter library which I do not understand but if this worked on linux it would be great as we (in house) have moved to c++11 and until libc++ can seat itself with some abi implementation that allows std::async etc. I am afraid I code/check/compile in clang and compile/run in gcc 4.6 and 4.7.

Thanks
David

Yes, it's almost enough for me to get to FreeBSD, particularly as I really like the bsd licence, sad as that may seem :-). I think 10 will be switched over completely to clang/libc++. I see libcxxab now reports to have nearly everything done for linux, but I cannot see how it's built at all, I hoped it would build with libc++ as part of cmake, but alas !!

We're using libcxxrt which was working on Linux, FreeBSD, and Solaris before libc++abi was started and has been tested a lot since then.

I think FreeBSD has libc++ set up as some filter library which I do not understand but if this worked on linux it would be great as we (in house) have moved to c++11 and until libc++ can seat itself with some abi implementation that allows std::async etc. I am afraid I code/check/compile in clang and compile/run in gcc 4.6 and 4.7.

FreeBSD now builds libstdc++ as a filter library for libsupc++. This allows us to swap out libsupc++ and replace it with libcxxrt without breaking anything that links to libstdc++ and got the (versioned) symbols from its embedded copy of libsupc++ before. You can add a line to libmap.conf to switch from libsupc++ to libcxxrt and so far everything I've tested has Just Worked™. I hope to get much wider testing for this when FreeBSD 9.1 ships with libc++ and libcxxrt out of the box.

This hackery is only required if you want to be able to link libraries built with the new stack against libraries built / linked with the old stack. If you are just wanting to use libc++, then building libc++ with -DLIBCXXRT and linking it against libcxxrt works fine. For FreeBSD 10, we don't plan on shipping libstdc++ at all in the default install, so this will likely be the default.

David

Thanks very much I am now fully working. I will continue to pull from the TOT. I manually installed libcxxabi and libc++.so* and it’s all operational now. Not sure if it was required but added -lcxxabi -lunwind to the libc++ CMakeCache file linker flags.

I have libc++ and libcxxabi in the projects folder of llvm, this keeps them all up to date (in sync) and I believe this is correct Ben, no doubt somebody will tell me if this is not the case.

The filter lib ideas sound excellent as well though with libcxxrt and libstdc++ set as filter libs to allow interoperability. Exciting times indeed !!

Superb work thanks very much all the clang/llvm teams this is as large as c++11 itself, really amazing work.

David [aka happy chap :slight_smile: ]

UPDATE !!

I had to switch to libcxxrt with some hassle (libcxxabi fixed threading but not async). To get this to statically compile I did have to use the buildit script in libcxx/lib dir. Adding the -l:libcxxrt.a as LDFLAGS and ifPIC as compile flags then in EXTRA_FLAGS add -DLIBCXXRT seems to do the trick if you have libcxxrt.a installed all OK.

then pass -ldl with all builds and it’s working.

Thanks again and hope this helps somebody else. If I get a chance I will check the CMake build in libcxx to see if there’s a simple way to add an option (USE_LIBCXXRT || USE_LIBCXXABI when it’s ready)

Thanks again, it’s great to be building in clang now ! several hard to find errors gone already.

David