I'm trying to compile a test case that employs dynamic_cast
using libc++, which was compiled according to "Build on Linux using CMake and libsupc++".
#include <iostream>
struct A
{
virtual void f(){ std::cout << "Virtual A" << std::endl; }
virtual ~A(){}
};
struct B : public A
{
void f() { std::cout << "Virtual B" << std::endl; }
virtual ~B(){}
};
int main()
{
A *a = new B;
B *b = dynamic_cast<B *>(a);
delete a;
}
I'm on ubuntu 13.04 and compiling with clang++ -std=c++11 -stdlib=libc++
.
Why I'm getting undefined reference to '__dynamic_cast'
? How to solve it?
EDIT
Looks like it has something to do with libc++abi since I'm seeing __dynamic_cast
prototype in the spec. I expected the libsupc++
first build option to work without such issues... and trying to compile libc++abi on linux is another issue itself.
This seems related to Compiling with Clang using Libc++ undefined references.
If this is indeed the problem, is there a straightforward process to use libc++ on linux that can compile that short snippet, or is it just not yet supported?
来源:https://stackoverflow.com/questions/16271976/undefined-reference-to-dynamic-cast-using-libc-on-ubuntu