简体   繁体   English

如何使用G ++抑制纯虚拟类的C ++ vtable生成?

[英]How do I suppress C++ vtable generation for pure virtual classes using G++?

Supressing C++ vtable generation can be done in MSVC using the __declspec(novtable) attribute. 可以使用__declspec(novtable)属性在MSVC中完成C ++ vtable的生成。 However, it seems that there is no equivalent attribute for the GNU C++ compiler. 但是,似乎GNU C ++编译器没有等效属性 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. 事实是,将纯虚拟类的vtable不必要地链接到__cxa_abort()和许多其他类中,并且我想避免这种情况的发生,因为我正在为嵌入式系统编程。 So, what should I do? 所以我该怎么做?

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

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

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

There is something that will achieve a similar result: #pragma interface . 有一些可以达到类似结果的东西: #pragma interface
#pragma implementation can override this, however. #pragma implementation可以覆盖此设置。
http://www.emerson.emory.edu/services/gcc/html/CPP_Interface.html http://www.emerson.emory.edu/services/gcc/html/CPP_Interface.html

The compiler flag -fno-rtti stops run-time type information generation. 编译器标志-fno-rtti停止运行时类型信息的生成。

In my experience with C++ on embedded platforms, this has prevented vtable compiler errors from occurring, suggesting it prevents them from being created (and consequentially, virtual functions won't work). 根据我在嵌入式平台上使用C ++的经验,这防止了vtable编译器错误的发生,这表明它阻止了它们的创建(因此,虚函数将不起作用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM