undefined reference to `__dynamic_cast' using libc++ on ubuntu

孤街浪徒 提交于 2019-12-02 16:55:28

问题


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?


回答1:


I would suggest using libcxxrt to replace the pretty Mac specific libc++abi (the website says only Darwin is supported). It provides a working implementation for BSD's Clang+libc++ setup, I believe it has been used with success on Linux as well.



来源:https://stackoverflow.com/questions/16271976/undefined-reference-to-dynamic-cast-using-libc-on-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!