I see people asking questions similar to this but not quite and always with code more complicated than mine. I have reduced my problem to the simplest possible terms:
Using Linux GCC compiler, this will build fine:
class MyBase
{
void Clear() {}
};
class MyDerived : public MyBase
{
void Clear() {}
};
This will not:
class MyBase
{
virtual void Clear() {}
};
class MyDerived : public MyBase
{
void Clear() {}
};
The link stage produces the following error:
/tmp/ccmEFi6P.o:(.rodata._ZTI9MyDerived[_ZTI9MyDerived]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/tmp/ccmEFi6P.o:(.rodata._ZTI6MyBase[_ZTI6MyBase]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
collect2: error: ld returned 1 exit status
Sorry, I am just getting used to the formatting system here.
OK, the compiler I am using is gcc and when I enter "gcc --version" I get:
gcc (GCC) 4.9.1
Copyright (C) 2014 Free Software Foundation, Inc.
The problem popped up while working with a much larger set of source files but I always like to try and reduce the code to the smallest bit as possible that still reproduces the problem. I have done this with a single source file:
derive.cpp:
class MyBase
{
virtual void Clear() {}
};
class MyDerived : public MyBase
{
void Clear() {}
};
int main()
{
MyDerived md;
return 0;
}
That is literaly all there is. It will build if I remove the "virtual" specifier from the base class' declaration of "Clear()". It will not build if I put it back. In both cases, my command line is:
gcc - o derive derive.cpp
and the full text of the build output is:
/tmp/cckxCssh.o:(.rodata._ZTI9MyDerived[_ZTI9MyDerived]+0x0): undefined
reference to `vtable for __cxxabiv1::__si_class_type_info'
/tmp/cckxCssh.o:(.rodata._ZTI6MyBase[_ZTI6MyBase]+0x0): undefined reference
to `vtable for __cxxabiv1::__class_type_info'
collect2: error: ld returned 1 exit status
Any help would be appreciated.