有两个DLL,GraphDll和RectDll。
在GraphDll中,Graph的定义如下
class AFX_EXT_CLASS CGraph : public CObject
{
DECLARE_DYNCREATE(CGraph);
public:
CGraph();
virtual ~CGraph();
virtual void Draw(CDC* pDC, BOOL bSec);
};
IMPLEMENT_DYNCREATE(CGraph, CObject)在RectDll中,CRectangle的定义
class AFX_EXT_CLASS CRectangle : public CGraph
{
DECLARE_DYNCREATE(CRectangle);
public:
CRectangle();
virtual ~CRectangle();
virtual void Draw(CDC* pDC, BOOL bSec);
};
IMPLEMENT_DYNCREATE(CRectangle, CGraph)在RectDll中已经静态装载了GraphDll.
编译GraphDll时,一切OK。
在编译RectDll时,会出现下面可恶的Link2001错误,各位帮帮忙吧。
--------------------Configuration: RectDll - Win32 Debug--------------------
Linking...
Creating library Debug/RectDll.lib and object Debug/RectDll.exp
Rectangle.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CGraph::classCGraph" (?classCGraph@CGraph@@2UCRuntimeClass@@B)
Debug/RectDll.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.RectDll.dll - 2 error(s), 0 warning(s)
在GraphDll中,Graph的定义如下
class AFX_EXT_CLASS CGraph : public CObject
{
DECLARE_DYNCREATE(CGraph);
public:
CGraph();
virtual ~CGraph();
virtual void Draw(CDC* pDC, BOOL bSec);
};
IMPLEMENT_DYNCREATE(CGraph, CObject)在RectDll中,CRectangle的定义
class AFX_EXT_CLASS CRectangle : public CGraph
{
DECLARE_DYNCREATE(CRectangle);
public:
CRectangle();
virtual ~CRectangle();
virtual void Draw(CDC* pDC, BOOL bSec);
};
IMPLEMENT_DYNCREATE(CRectangle, CGraph)在RectDll中已经静态装载了GraphDll.
编译GraphDll时,一切OK。
在编译RectDll时,会出现下面可恶的Link2001错误,各位帮帮忙吧。
--------------------Configuration: RectDll - Win32 Debug--------------------
Linking...
Creating library Debug/RectDll.lib and object Debug/RectDll.exp
Rectangle.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CGraph::classCGraph" (?classCGraph@CGraph@@2UCRuntimeClass@@B)
Debug/RectDll.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.RectDll.dll - 2 error(s), 0 warning(s)
我已经如你们所说的那样早已包含了lib,问题不是处在这里的。
仔细瞧瞧吧?谢谢!
问题是现在如何绕过MFC的这一个规定?
create a new macro.hmacro.h
//begin
#ifdef EXPORT_CLASS
#undef EXPORT_CLASS
#endif
#ifdef _BUILD_DLL
#define EXPORT_CLASS __declspec(dllexport)
#else
#define EXPORT_CLASS __declspec(dllimport)
//end in you dll project setting c/c++ propcessor definitions add such:_BUILD_DLLand in you Graph and CRectangle的定义文件中
add #include "macro.h"
并使用 EXPORT_CLASS
代替 AFX_EXT_CLASS
#endif//_BUILD_DLL
//end