When building my C++ program, I\'m getting the error message
undefined reference to \'vtable...
What is the cause of this probl
CDasherComponent
has a body for the destructor? It's definitely not here - the question is if it is in the .cc file.CDasherModule
should explicitly define its destructor virtual
.CGameModule
has an extra }
at the end (after the }; // for the class
).CGameModule
being linked against the libraries that define CDasherModule
and CDasherComponent
?For what it is worth, forgetting a body on a virtual destructor generates the following:
undefined reference to `vtable for CYourClass'.
I am adding a note because the error message is deceptive. (This was with gcc version 4.6.3.)
I simply got this error because my .cpp file was not in the makefile.
In general, if you forget to compile or link to the specific object file containing the definition, you will run into this error.
In my case I'm using Qt and had defined a QObject
subclass in a foo.cpp
(not .h
) file. The fix was to add #include "foo.moc"
at the end of foo.cpp
.
If you are using Qt, try rerunning qmake. If this error is in the widget's class, qmake might have failed to notice that the ui class vtable should be regenerated. This fixed the issue for me.
If all else fails, look for duplication. I was misdirected by the explicit initial reference to constructors and destructors until I read a reference in another post. It's any unresolved method. In my case, I thought I had replaced the declaration that used char *xml
as the parameter with one using the unnecessarily troublesome const char *xml
, but instead, I had created a new one and left the other one in place.