如果有两个扩展DLL:A.DLL, and B.DLL。类定义形式如下:
一个工程中:
// A.H
class AFX_EXT_CLASS CExampleA : public CObject
{
DECLARE_DYNCREATE(CExampleA )
... class definition ...
};另一个工程中:
// B.H
class AFX_EXT_CLASS CExampleB : public CExampleA
{
DECLARE_DYNCREATE(CExampleB )
... class definition ..
};
结果出现下面的问题:
Generating Code...
Linking...
ExampleB.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CExampleA::classCExampleA" (?classCExampleA@CExampleA@@2UCRuntimeClass@@B)
Debug/B.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Creating browse info file...B.dll - 2 error(s), 0 warning(s)后来,我又尝试下面的方法
// A.H
#ifdef A_IMPL
#define CLASS_DECL_A __declspec(dllexport)
#else
#define CLASS_DECL_A __declspec(dllimport)
#endifclass CLASS_DECL_A CExampleA : public CObject
{
DECLARE_DYNCREATE(CExampleA )
... class definition ...
};// B.H
#ifdef B_IMPL
#define CLASS_DECL_B __declspec(dllexport)
#else
#define CLASS_DECL_B __declspec(dllimport)
#endifclass CLASS_DECL_B CExampleB : public CExampleA
{
DECLARE_DYNCREATE(CExampleB )
... class definition ..
};
出现了
error C2491: CExampleA::classCExampleA' : definition of dllimport static data member not allowed
error C2491: 'CExampleB::classCExampleB' : definition of dllimport static data member not allowed
一个工程中:
// A.H
class AFX_EXT_CLASS CExampleA : public CObject
{
DECLARE_DYNCREATE(CExampleA )
... class definition ...
};另一个工程中:
// B.H
class AFX_EXT_CLASS CExampleB : public CExampleA
{
DECLARE_DYNCREATE(CExampleB )
... class definition ..
};
结果出现下面的问题:
Generating Code...
Linking...
ExampleB.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CExampleA::classCExampleA" (?classCExampleA@CExampleA@@2UCRuntimeClass@@B)
Debug/B.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Creating browse info file...B.dll - 2 error(s), 0 warning(s)后来,我又尝试下面的方法
// A.H
#ifdef A_IMPL
#define CLASS_DECL_A __declspec(dllexport)
#else
#define CLASS_DECL_A __declspec(dllimport)
#endifclass CLASS_DECL_A CExampleA : public CObject
{
DECLARE_DYNCREATE(CExampleA )
... class definition ...
};// B.H
#ifdef B_IMPL
#define CLASS_DECL_B __declspec(dllexport)
#else
#define CLASS_DECL_B __declspec(dllimport)
#endifclass CLASS_DECL_B CExampleB : public CExampleA
{
DECLARE_DYNCREATE(CExampleB )
... class definition ..
};
出现了
error C2491: CExampleA::classCExampleA' : definition of dllimport static data member not allowed
error C2491: 'CExampleB::classCExampleB' : definition of dllimport static data member not allowed
#include "a.h"
#pragma comment( lib , "a.lib" )
我在B.h中已经有了这样的代码了。
已经包含了头。
什么意思?能不能详细点?
谢谢!
AFX_EXT_CLASS-->AFX_CLASS_EXPORT
Generating Code...
Linking...
ExampleB.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CExampleB::classCExampleB" (?classCExampleB@CExampleB@@2UCRuntimeClass@@B)
Debug/B.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Creating browse info file...
dll分debug和release,lib不分.注意:如果h文件有变化,也要更新应该没有问题.我已经做了n次了
[email protected]
我把工程发给你了,请查收!
Project->Setting->c/c++->Process definition
加入: CLASS_DECL_B and CLASS_DECL_A
#define COMMON_IMPORT_EXPORT _declspec(dllexport)
#else
#define COMMON_IMPORT_EXPORT _declspec(dllimport)
#endif
我早已试过了,不行!
查看了你发回的工程,你改动了我的关键部分,不行的。我回信给你了。