I'm trying to export a class and its base class from a DLL like this:
#ifdef MY_EXPORTS
#define DECLSPEC_TEST __declspec(dllexport)
#else
#define DECLSPEC_TEST __declspec(dllimport)
#endif
class DECLSPEC_TEST BaseClass
{
// stuff.
};
class DECLSPEC_TEST DerivedClass : public BaseClass
{
// This class only has a constructor which initializes the class differently.
};
But I try to use this class in another DLL, I keep getting an error:
error LNK2019: unresolved external symbol
"__declspec(dllimport) public: __thiscall DerivedClass::DerivedClass(void)"
(__imp_??0DerivedClass@@QAE@XZ) referenced in function
"public: __thiscall SomeOtherClass::SomeOtherClass(void)" (??0SomeOtherClass@@QAE@XZ)
I also looked at my exporting DLL with PE Explorer and I can't see the derived class in the exports list.
When I try to use the base class in my other DLL it works fine.
What am I doing wrong?
there are two ways to load the DLL. The first is to reference one or more symbols from the DLL (your classname, for example), supply an appropriate import .LIB and let the linker figure everything out.
The second is to explicitly load the DLL via LoadLibrary.
Either approach works fine for C-level function exports. You can either let the linker handle it or call GetProcAddress as you noted.
But when it comes to exported classes, typically only the first approach is used, i.e., implicitly link to the DLL.
Ok, I don't know how to explain this but I put the implementation of the derived class' constructor in a CPP file instead of within the class definition and the error went away...
thanks everybody :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With