在ubuntu上使用libc ++未定义引用`__dynamic_cast' [英] undefined reference to `__dynamic_cast' using libc++ on ubuntu

查看:496
本文介绍了在ubuntu上使用libc ++未定义引用`__dynamic_cast'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译一个测试用例,它使用libc ++使用 dynamic_cast ,它是根据使用CMake和libsupc ++在Linux上构建

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;
}

我在Ubuntu 13.04上,并且使用 clang ++ -std = c ++ 11 -stdlib = libc ++

I'm on ubuntu 13.04 and compiling with clang++ -std=c++11 -stdlib=libc++.

为什么我得到未定义的引用'__dynamic_cast '?如何解决?

Why I'm getting undefined reference to '__dynamic_cast'? How to solve it?

看起来像它与libc ++有关abi ,因为我在规格中看到 __ dynamic_cast 原型 。我希望 libsupc ++ 第一个构建选项工作没有这样的问题...并试图编译libc ++ abi on linux 是另一个问题本身

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.

似乎与使用Libc ++编译未定义的引用相关。

如果此确实是问题,是否有一个简单的过程在linux上使用libc ++,可以编译那个短片段,或者它只是还不支持?

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?

推荐答案

我建议使用 libcxxrt 替换漂亮的Mac特定 libc ++ abi (网站说只有达尔文支持)。它提供了一个BSD的Clang + libc ++安装的工作实现,我相信它已经在Linux上成功使用。

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.

这篇关于在ubuntu上使用libc ++未定义引用`__dynamic_cast'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆