静态链接MFC库的问题

Mor*_*nar 1 c++ dll linker mfc

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

该解决方案由三个项目组成,例如A,B,C.C是活动项目,输出.dll并依赖于B.B输出.lib并依赖于A. A输出.lib.

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

一切都正确建立,直到最后的链接阶段,我看到这一点:

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)
Run Code Online (Sandbox Code Playgroud)

我用Google搜索了这个问题,看到了其他有类似问题的人,但似乎无法解决它.我尝试将Nafxcw.lib添加到C的Ignored库中,但这会将这批链接器错误转换为1500多个未解决的符号错误.我可以让它编译/链接,如果我让它动态链接MFC,但就像我说的,我需要它静态链接.我觉得我错过了一些相当简单但似乎无法绕过它的东西.任何和所有随机的想法和想法将不胜感激.

Mor*_*nar 5

通常情况下,解决方案变得如此平凡和明显,我仍然在踢我自己的头很长时间.

基本上,上面引用的项目A不是我直接从旧的VS6工作空间中提取的项目,而是之前由另一个团队转换以在另一个应用程序中使用的项目.我认为它是功能上等同于原有的一个,但是这是非常多的情况并非如此.这些链接错误是实际的,有效的多重定义的链接错误.当我开始挖掘时,我发现第一批错误来自multimon.h项目A(我甚至不需要,只是删除它),第二批来自A和B中实际定义的类. .

就像我说的那样,我仍然在这里呻吟,但至少我现在应该可以解决我的问题了.感谢您的帮助,永远记住永远不要假设任何事情.