Wednesday, March 5, 2014

Undefined reference to class constructor

We've all seen it, but not all that often so in case you have forgotten the fix... as I did... here is the deal:

 undefined reference to `vtable for Namespace::Namespace::ClassName line # (end of constructor)

And you look and it all seems fine... but maybe you did some refactoring and left a method declaration that happens to be virtual, but is no longer implemented... (oops, I did)

Very helpful SO post on the topic and at the bottom the best info

The GCC FAQ has an entry on it:

The solution is to ensure that all virtual methods that are not pure are defined. Note that a destructor must be defined even if it is declared pure-virtual [class.dtor]/7.


Identify the extra method declaration and say goodbye to your linker error :-)