32

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.

1
  • All mentioned undefined references are defined in the libc++abi: abi-laboratory.pro/… Commented Feb 26, 2017 at 11:13

4 Answers 4

17

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++

Sign up to request clarification or add additional context in comments.

5 Comments

Well slap me in the face and call me nancy, that looks like it. Can I link against both of them and cover the spectrum?
that might be possible, if you're very careful to specify the libraries in the right order to your linker, and make sure you understand how your linker treats the order of objects and how it resolves symbols that might be defined in multiple places.
OK, so I downloaded libc++abi and linked it in and got all the errors gone except for typeinfo for char const* and __gxx_personality_v0.
Forgive my ignorance, but how do you specify this?
Nevermind, it seems to be -stdlib=libc++ but what worked for me was -lstdc++.6
5

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.

Comments

3

This seems like you are using exception handling, but it isn't enabled in the compiler. Try passing -fexceptions to the commandline.

Comments

2

I'm only adding this answer as I literally made this mistake just now. It was compiling most of what I was writing just fine for days, but now it starts throwing undefined reference errors...

So... I... sorta possibly was compiling with clang not clang++. Yeah. That was all that was wrong. clang++ includes C++ library stuff, clang doesn't. Oops!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.