I'm beginning to work on a plugin framework for an application, which will work by dynamically loading shared/dynamic libraries that contain classes (unknown to the application) that derive from base classes (known to the application).
I'm using MinGW with GCC and GNU-Make. The compiler output is below, including the rather strange linker error.
g++ -DBUILDING_DLL -c -o plugin.o classes.cpp
g++ -shared -o plugin.dll plugin.o
plugin.o:classes.cpp:(.text$_ZN9baseClassC2Ev[baseClass::baseClass()]+0x8): undefined reference to `vtable for baseClass'
collect2: ld returned 1 exit status
mingw32-make: *** [plugin.dll] Error 1
The problem appears to be in baseClass' constructor, which I haven't defined. I get the same error, but twice, if I define baseClass' constructor as 'baseClass() {}', as I did with derivedClass (see code).
The code isn't too long, I'll post it below. Help is appreciated. I think I'm doing something wrong with constructors, but I'm not sure what.
As you can see, I also took your advice and made the destructor virtual. Omitting it didn't make a difference to compilation, but if you think it's a good idea, then thanks for the advice!
If you do not declare the base class destructor as virtual, then derived classes that need to free resources in their destructors will never get called from a base class pointer.