C++ “non-virtual thunk to <method name>”,引用自:<objectfile.o> 中 <classname> 的 Vtable
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5831063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"non-virtual thunk to <method name>", referenced from: Vtable for <classname>in <objectfile.o>
提问by rahzark
When compiling in debug mode my xcode compilation has these linking errors:
在调试模式下编译时,我的 xcode 编译有以下链接错误:
"<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.
奇怪的是:它只出现在我的构建目标之一中(该代码的两个目标几乎相同),而且如果这些方法是在头文件中而不是 .cpp 中定义的,那么它对两个目标都可以正常工作。
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?
任何人都知道是什么导致了这个错误?
回答by neutrino38
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).
遇到了同样的问题。它只是在我们定义了一个虚拟成员函数(在 .h 头文件中)但没有实现它(在 .cpp 文件中)时发生。
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
在我的例子中,实现是在一个 #define 中,它阻止了实际编译。GCC 应该针对此类常见错误提供更明确的信息,例如
virtual function <function> defined but not implemented in class <class>
回答by justin
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 candefine a pure virtual).
我们将从明显的部分开始:这表明 cpp 未链接,或者调用被直接引用且未定义(您可以定义纯虚拟)。
beyond that, there may be differences in build settings - generally, this is because of default symbol visibility (Xcode alias flags, and recommended settings):
除此之外,构建设置可能存在差异 - 通常,这是因为默认符号可见性(Xcode 别名标志和推荐设置):
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.
还有一些其他构建设置可能会产生干扰——不知道你的项目是如何构建的,所以......这个列表可能会变得相当大。