Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"non-virtual thunk to <method name>", referenced from: Vtable for <classname>in <objectfile.o>

Tags:

c++

xcode

linker

When compiling in debug mode my xcode compilation has these linking errors:

"<method name>", referenced from: 
Vtable for <classname>in <objectfile.o>

"non-virtual thunk to <method name>", referenced from: 
Vtable for <classname>in <objectfile.o>

the strange thing is: It only occurs in one of my build targets (both targets are pretty much the same for that code), plus if these methods are defined in the header file instead of the .cpp it works fine for both targets.

All of those methods are pure virtual. The class where these errors occur inherits from multiple classes but only one of those causes these errors.

Anyone has any idea of what is causing this error?

like image 580
rahzark Avatar asked Apr 29 '11 10:04

rahzark


People also ask

What is the difference between vtable and typeinfo?

Show activity on this post. vtable and typeinfo are internal structures generated by the C++ compiler. vtable is used for calling virtuable functions and typeinfo is used for RTTI. Different compilers have different strategies for when they generate these structures.

How to declare an obstacle as a pure virtual class?

If Obstacle is an abstract base class, then make sure you declare all its virtual methods "pure virtual": The = 0 tells the compiler that this method must be overridden by a derived class, and might not have its own implementation.

What does the = 0 mean in a method name?

The = 0 tells the compiler that this method must be overridden by a derived class, and might not have its own implementation.


2 Answers

Got hit by the same issue. It simply happened when we defined a virtual member function (in the .h header file) but not implemented it (in the .cpp file).

In my case, the implementation was inside a #define that prevented to be actually compiled. GCC should have more explicit message for that kind of common mistake such as

virtual function <function> defined but not implemented in class <class>
like image 166
neutrino38 Avatar answered Sep 22 '22 09:09

neutrino38


Encountered this issue when developing with C++/QtCreator, it was caused by including the same file multiple times in the .pro file. Make sure to check each necessary header/source file is only listed under HEADERS += \ and SOURCES += \ once!

like image 31
SeanTwomey Avatar answered Sep 20 '22 09:09

SeanTwomey