代码之家  ›  专栏  ›  技术社区  ›  Morinar

静态链接MFC库时出现的问题

  •  1
  • Morinar  · 技术社区  · 16 年前

    我有一个VisualStudio6工作区,我正试图转换为VisualStudio2008解决方案。所述解决方案的输出为.dll。它必须是一个.dll,它需要静态链接MFC,因为我无法将MFC重新分发给现有客户。

    在常规配置属性中,我将A和B设置为静态库(.lib),将C设置为动态库(.dll)。所有三个项目都设置为“在静态库中使用MFC”。此外,对于运行库,所有三个项目都设置为“多线程”,并且没有一个项目定义了_afxdl。

    1>nafxcw.lib(wincore.obj) : error LNK2005: _IsPlatformNT already defined in A.lib(Globals.obj)
    1>nafxcw.lib(wincore.obj) : error LNK2005: _InitMultipleMonitorStubs already defined in A.lib(Globals.obj)
    1>nafxcw.lib(wincore.obj) : error LNK2005: _xGetSystemMetrics@4 already defined in A.lib(Globals.obj)
    1>nafxcw.lib(wincore.obj) : error LNK2005: _xMonitorFromPoint@12 already defined in A.lib(Globals.obj)
    1>nafxcw.lib(wincore.obj) : error LNK2005: _xMonitorFromRect@8 already defined in A.lib(Globals.obj)
    1>nafxcw.lib(wincore.obj) : error LNK2005: _xMonitorFromWindow@8 already defined in A.lib(Globals.obj)
    1>nafxcw.lib(wincore.obj) : error LNK2005: _xGetMonitorInfo@8 already defined in A.lib(Globals.obj)
    1>nafxcw.lib(wincore.obj) : error LNK2005: _xEnumDisplayMonitors@16 already defined in A.lib(Globals.obj)
    1>nafxcw.lib(wincore.obj) : error LNK2005: _xEnumDisplayDevices@16 already defined in A.lib(Globals.obj)
    1>nafxcw.lib(wincore.obj) : error LNK2005: _g_pfnGetSystemMetrics already defined in A.lib(Globals.obj)
    1>nafxcw.lib(wincore.obj) : error LNK2005: _g_pfnMonitorFromWindow already defined in A.lib(Globals.obj)
    1>nafxcw.lib(wincore.obj) : error LNK2005: _g_pfnMonitorFromRect already defined in A.lib(Globals.obj)
    1>nafxcw.lib(wincore.obj) : error LNK2005: _g_pfnMonitorFromPoint already defined in A.lib(Globals.obj)
    1>nafxcw.lib(wincore.obj) : error LNK2005: _g_pfnGetMonitorInfo already defined in A.lib(Globals.obj)
    1>nafxcw.lib(wincore.obj) : error LNK2005: _g_pfnEnumDisplayMonitors already defined in A.lib(Globals.obj)
    1>nafxcw.lib(wincore.obj) : error LNK2005: _g_pfnEnumDisplayDevices already defined in A.lib(Globals.obj)
    1>nafxcw.lib(wincore.obj) : error LNK2005: _g_fMultiMonInitDone already defined in A.lib(Globals.obj)
    1>nafxcw.lib(wincore.obj) : error LNK2005: _g_fMultimonPlatformNT already defined in A.lib(Globals.obj)
    1>nafxcw.lib(viewprnt.obj) : error LNK2005: "public: virtual int __thiscall CPrintingDialog::OnInitDialog(void)" (?OnInitDialog@CPrintingDialog@@UAEHXZ) already defined in B.lib(ImagePropertiesDlg.obj)
    1>nafxcw.lib(viewprnt.obj) : error LNK2005: "public: __thiscall CPrintingDialog::CPrintingDialog(class CWnd *)" (??0CPrintingDialog@@QAE@PAVCWnd@@@Z) already defined in B.lib(ImagePropertiesDlg.obj)
    1>nafxcw.lib(viewprnt.obj) : error LNK2005: "public: virtual void __thiscall CPrintingDialog::OnCancel(void)" (?OnCancel@CPrintingDialog@@UAEXXZ) already defined in B.lib(ImagePropertiesDlg.obj)
    

    我在谷歌上搜索到这个问题,看到其他人也有类似的问题,但似乎无法解决。我尝试将nafxcw.lib添加到C忽略的库中,但这将这批链接器错误转化为1500多个未解决的符号错误。我可以让它编译/链接,如果我让它动态链接MFC,但就像我说的,我 需要

    2 回复  |  直到 16 年前
        1
  •  5
  •   Morinar    16 年前

    就像通常的情况一样,这个解决方案被证明是如此的平凡和明显,我仍然在为我的头撞了这么久而自责。

    基本上,上面提到的项目A不是我直接从旧的VS6工作区中提取的项目,而是以前由另一个团队转换用于另一个应用程序的项目。我 假定 它在功能上与原来的一样,但实际上 非常 multimon.h 在项目A中(一些我甚至不需要的东西,只是删除了它),第二批来自于一个在A和B中实际定义的类。

    就像我说的,我还在这里呻吟,但至少我现在可以解决我的问题了。谢谢你的帮助,永远记住不要做任何假设。

        2
  •  0
  •   John D.    16 年前

    当您尝试忽略nafxcw库时,是否按照建议将其重新添加以尝试强制链接顺序 this