C ++中的DLL导出和继承 [英] DLL export and inheritance in C++
问题描述
我正在尝试从DLL中导出一个类及其基类,如下所示:
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.
};
但是我尝试在另一个DLL中使用此类,但我不断收到错误消息:
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)
我还用PE Explorer查看了导出的DLL,但在导出列表中看不到派生类.
I also looked at my exporting DLL with PE Explorer and I can't see the derived class in the exports list.
当我尝试在其他DLL中使用基类时,效果很好.
When I try to use the base class in my other DLL it works fine.
我做错了什么?
推荐答案
好,我不知道如何解释这个问题,但是我将派生类的构造函数的实现放在CPP文件中,而不是在类定义中,错误消失了...
谢谢大家:)
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 :)
这篇关于C ++中的DLL导出和继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!