Abstract classes in a shared library
I have a regular abstract class that has a couple of pure virtual methods. The class itself is part of the shared library. Compiling the shared library itself is fine. But when a library is linked to another program that has another class derived from an abstract in a shared library and defining pure virtual methods, I get the following linker error.
I compile like this:
g++ -I../path/to/the/library main.cpp derived.cpp -L../path/to/the/library -lsomename -o shared
Linker error:
libsomename.so: undefined reference to `AbstractClass :: method () '
It looks like the abstract class cannot access its pure virtual methods, but I am not trying to make any instance of the abstract class anywhere in the library.
What could be the problem?
a source to share
When defining abstract classes, you must make all functions virtual and also end up with = 0 ie:
class DPReporterI
{
public:
virtual uint32 getProviderCount()=0;
virtual uint32 getProviderId(uint32 index)=0;
virtual uint32 getLastRate(uint32 id)=0;
virtual void getName(uint32 id, char* buff, uint32 size)=0;
};
Make sure you have done this and it should work.
a source to share