如果有两个扩展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

解决方案 »

  1.   

    B.h中
    #include  "a.h"
    #pragma comment( lib , "a.lib" )
      

  2.   

    to Free_Man(浪迹天涯) :
    我在B.h中已经有了这样的代码了。
      

  3.   

    to bdove(不再灌水) :
      已经包含了头。
      

  4.   

    把AFX_EXT_CLASS从新定义一个名字
      

  5.   

    to  bauhaus(地狱里天使的吟唱) :
    什么意思?能不能详细点?
    谢谢!
      

  6.   

    对了,bauhaus(地狱里天使的吟唱)提醒了一下,如果楼主想导出一个类用以下:
    AFX_EXT_CLASS-->AFX_CLASS_EXPORT
      

  7.   

    按照  Free_Man(浪迹天涯) 说得那样做了,仍然出现:
    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...
      

  8.   

    那就顺序编译A,然后将新生成的lib文件和dll文件copy到适当的位置.
    dll分debug和release,lib不分.注意:如果h文件有变化,也要更新应该没有问题.我已经做了n次了
      

  9.   

    干脆,给我工程,我来给你编译一下.
    [email protected]
      

  10.   

    to Free_Man(浪迹天涯) :
    我把工程发给你了,请查收!
      

  11.   

    是不是忘记
    Project->Setting->c/c++->Process definition
    加入: CLASS_DECL_B and CLASS_DECL_A
      

  12.   

    将AFX_EXT_CLASS替换掉#ifdef COMMON_DLL
    #define COMMON_IMPORT_EXPORT _declspec(dllexport)
    #else
    #define COMMON_IMPORT_EXPORT _declspec(dllimport)
    #endif
      

  13.   

    ColderRain(莫走重辄路) :
       我早已试过了,不行!
      

  14.   

    Free_Man(浪迹天涯) :
        查看了你发回的工程,你改动了我的关键部分,不行的。我回信给你了。
      

  15.   

    该问题已经结贴。Free_Man(50),ColderRain(50)。