Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Ask Question

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?

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>
                @underscore_d I think I must diagree. class declaration class Foo;. Class definition class Foo{int a;}; . Class implementation AFAIK is there, where you have method defined, so in .cpp file. Please see stackoverflow.com/questions/1410563/….
– DawidPi
                Jan 25, 2017 at 10:55
                @DawidPi But you're talking about something different. The other two of us were talking about the member function, not the class. Specifying the signature of the member function in the class definition is a function declaration.
– underscore_d
                Jan 25, 2017 at 15:17

we'll start with the obvious bits: this suggests that the cpp is not linked in, or that the calls are referenced directly and not defined (you can define a pure virtual).

beyond that, there may be differences in build settings - generally, this is because of default symbol visibility (Xcode alias flags, and recommended settings):

GCC_INLINES_ARE_PRIVATE_EXTERN = NO
GCC_SYMBOLS_PRIVATE_EXTERN = NO

there are a few other build settings which could interfere -- idk how your projects are structured so... this list can become rather large.

Just run into this problem with a linked C++ library. Could you clarify, whether those settings you mention above are the values they should be or the (possibly incorrect) default values? – JOM Sep 18, 2013 at 6:49 @JOM assume NO if you do not know the author's intent. also ensure your exception and rtti info is generated like in the dylib, and finally, verify that the virtual functions of that type all have definitions (if the source is available). – justin Sep 18, 2013 at 10:43

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.