Alex Rivera | Logout

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

Asked 2011-12-03T22:17:04.173
9

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()
{
    //...
}
Edit
Report

1 Answer

0

The compiler flag -fno-rtti stops run-time type information generation.

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).

answered 2013-04-24T00:33:22.323

Your Answer