PDA

View Full Version : Quick question regarding abstract classes and DLLs



durbrak
8th February 2007, 22:25
Hello,
I have a rather simple question which I can't solve on my own because I'm still a rookie :)
Anyway, I have my main application (main.exe) and a module.dll. My application has an AbstractModule class for custom modules and the module.dll uses this.

AbstractModule.h


//.h
class AbstractModule
{
public:
virtual QString name() const = 0;
bool isSomething() const;
};

//.cpp
bool AbstractModule::isSomething()
{
return true;
}


Now I create a separate module dll for the first module ("module.dll") and it uses the "abstractmodule.h":


//.h
#include <abstractmodule.h>
class Module : public AbstractModule
{
public:
Module();

QString name() const;
};

//.cpp
Module::Module()
{
bool isIt = this->isSomething(); //Link error (LNK2019)
}
QString Module::name() const
{
return "Test";
}


In Visual Studio I set the "module.dll"-project to be dependent on the "main.exe"-project.
But when I try to compile the solution I get a link error:

error LNK2019: unresolved external symbol [...]
I guess it has somehow to do with the fact that the definition of AbstractModule::isSomething() is in the .exe?
I'm sorry, but I'm totally new to this whole dll stuff :)
Thank you for your help.

wysota
8th February 2007, 22:32
If the abstract module has at least one method actually implemented, you have to add the definition to the dll as well, you can't make a dll depend on an exe (only the other way round).

Hint: You can define some methods in the header file, so you don't have to add any cpp files to your library.