如何使用G ++抑制纯虚拟类的C ++ vtable生成? [英] How do I suppress C++ vtable generation for pure virtual classes using G++?

查看:57
本文介绍了如何使用G ++抑制纯虚拟类的C ++ vtable生成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用 __ declspec(novtable)属性在MSVC中完成C ++ vtable的生成.但是,似乎没有等效属性,GNU C ++编译器.事实是,将纯虚拟类的vtable不必要地链接到 __ cxa_abort()和许多其他链接中,并且我想避免这种情况的发生,因为我正在为嵌入式系统编程.那么,我该怎么办?

Supressing C++ vtable generation can be done in MSVC using the __declspec(novtable) attribute. However, it seems that there is no equivalent attribute for the GNU C++ compiler. The fact is that leaving the vtables for pure virtual classes unnecessarily links in __cxa_abort() and many others, and I want to avoid this happening because I'm programming for an embedded system. So, what should I do?

struct ISomeInterface
{
    virtual void Func() = 0;
};

class CSomeClass : public ISomeInterface
{
    virtual void Func();
}

void CSomeClass::Func()
{
    //...
}

推荐答案

有些东西会达到类似的结果: #pragma接口.
但是, #pragma实现可以覆盖它.
http://www.emerson.emory.edu/services/gcc/html/CPP_Interface.html

There is something that will achieve a similar result: #pragma interface.
#pragma implementation can override this, however.
http://www.emerson.emory.edu/services/gcc/html/CPP_Interface.html

这篇关于如何使用G ++抑制纯虚拟类的C ++ vtable生成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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