Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling with Clang using Libc++ undefined references

The first couple are too long to reference. I get this error when I try to compile clang++ -stdlib=libc++ ../main.cc ... with clang and libc++ from the SVN.

error: undefined reference to 'typeinfo for char const*' error: undefined reference to '__cxa_allocate_exception' error: undefined reference to '__cxa_throw' /tmp/cc-pbn00y.o:../main.cc:function std::__1::deque<double, std::__1::allocator<double> >::__add_back_capacity(): error: undefined reference to '__cxa_begin_catch' /tmp/cc-pbn00y.o:../main.cc:function std::__1::deque<double, std::__1::allocator<double> >::__add_back_capacity(): error: undefined reference to '__cxa_rethrow' /tmp/cc-pbn00y.o:../main.cc:function std::__1::deque<double, std::__1::allocator<double> >::__add_back_capacity(): error: undefined reference to '__cxa_end_catch' /tmp/cc-pbn00y.o(.eh_frame+0xbd3): error: undefined reference to '__gxx_personality_v0' 

SOLUTION: Thanks to one of the answers, I know the solution. libc++ can't be used by itself like libstdc++, it has to be linked along with libc++abi. However, libc++abi isn't complete yet, so using libc++ seems to be a little incomplete for the moment, but it is still my first choice when it completes.

UPDATE 5/26/2012: libc++abi is now complete for C++ and I have been using clang++ as follows successfully clang++ -std=c++11 -stdlib=libc++ -lc++abi.

like image 486
norcalli Avatar asked Aug 10 '11 19:08

norcalli


2 Answers

I believe libc++ doesn't support all exception functions yet. See the status page:

http://libcxxabi.llvm.org/spec.html

You could probably link against gnu's libstdc++

like image 71
Arvid Avatar answered Sep 18 '22 02:09

Arvid


Here's what works for me with the Ubuntu Vivid packages for clang and libc++:

clang++ -std=c++11 -stdlib=libc++ <object files> -lc++abi -lsupc++ 

It is important that the object files come before the -l flags, e.g. when you use exceptions. Obviously, this still will not link if you use libraries compiled against libstdc++ and use any STL types in those interfaces.

like image 23
Vir Avatar answered Sep 20 '22 02:09

Vir