2009-11-18 112 views
1

我有一个Visual Studio 6工作区我试图转换为Visual Studio 2008解决方案。该解决方案的输出是一个.dll。它必须是.dll,它需要静态链接MFC,因为我无法将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: [email protected] already defined in A.lib(Globals.obj) 
1>nafxcw.lib(wincore.obj) : error LNK2005: [email protected] already defined in A.lib(Globals.obj) 
1>nafxcw.lib(wincore.obj) : error LNK2005: [email protected] already defined in A.lib(Globals.obj) 
1>nafxcw.lib(wincore.obj) : error LNK2005: [email protected] already defined in A.lib(Globals.obj) 
1>nafxcw.lib(wincore.obj) : error LNK2005: [email protected] already defined in A.lib(Globals.obj) 
1>nafxcw.lib(wincore.obj) : error LNK2005: [email protected] already defined in A.lib(Globals.obj) 
1>nafxcw.lib(wincore.obj) : error LNK2005: [email protected] 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)" ([email protected]@@UAEHXZ) already defined in B.lib(ImagePropertiesDlg.obj) 
1>nafxcw.lib(viewprnt.obj) : error LNK2005: "public: __thiscall CPrintingDialog::CPrintingDialog(class CWnd *)" ([email protected]@[email protected]@@@Z) already defined in B.lib(ImagePropertiesDlg.obj) 
1>nafxcw.lib(viewprnt.obj) : error LNK2005: "public: virtual void __thiscall CPrintingDialog::OnCancel(void)" ([email protected]@@UAEXXZ) already defined in B.lib(ImagePropertiesDlg.obj) 

我GOOGLE了这个问题死刑,并看到其他人有similarish的问题,但似乎无法来解决这个问题。我尝试将nafxcw.lib添加到C的忽略库中,但是这将这批链接器错误转换为1500多个未解决的符号错误。我可以把它编译/链接,如果我让它动态链接MFC,但正如我所说,我需要它静态链接。我觉得我错过了一些相当简单的事情,但似乎无法将其包围。任何和所有随机的想法和想法将不胜感激。

回答

5

与往常一样,这个解决方案竟然是如此的平凡和明显,我仍然在踢我自己的头撞了很长时间。

基本上,上面引用的项目A不是我直接从旧VS6工作区中提取的项目,而是之前由另一个团队转换用于其他应用程序的项目。我假设它在功能上等同于原来的那个,但那是非常非常不一样的情况。这些链接错误是实际的,有效的乘法定义的链接错误。当我开始深入研究时,我发现第一批错误来自于项目A中的multimon.h(我甚至不需要它,只是将其删除),第二批来自一个实际在A和A中定义的类B.

就像我说的,我还在这里呻吟,但至少我现在应该能够解决我的问题。感谢您的帮助,并永远记住永远不要承担任何责任。

0

当您尝试忽略nafxcw库时,是否将其重新添加以尝试强制执行this KB文章中建议的链接顺序?虽然你的问题不是一个确切的适合它可能是相关的。也许事情可以通过链接顺序来解决。

+0

是的,我试过了。在这两个地方看起来绝对没有什么。 – Morinar 2009-11-18 20:42:32

+0

你可以发布你使用的命令行编译器选项吗? – 2009-11-18 20:53:31

+0

您是否忽略了错误消息中报告的*库*,然后在将它们添加回链接行时交换它们的顺序?并不是说我正在努力解决这个问题或任何问题,但这个答案并没有明确地表明这一点。过去我曾多次遭受过你的问题,而且“修复”一直对我有用。 – 2009-11-18 20:59:57