1

我有一个 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)

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

4

2 回答 2

5

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

基本上,上面引用的项目 A 不是我直接从旧的 VS6 工作区中提取的项目,而是之前由另一个团队转换为在另一个应用程序中使用的项目。我认为它在功能上与原始版本相同,但事实并非如此。这些链接错误是实际的、有效的多重定义链接错误。当我开始深入研究时,我发现第一批错误来自包含multimon.h在项目 A 中(我什至不需要,只是将其删除),第二批来自实际在 A 和 B 中定义的类.

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

于 2009-11-18T21:00:47.620 回答
0

当您尝试忽略 nafxcw 库时,您是否将其重新添加以尝试按照知识库文章的建议强制链接顺序?虽然您的问题并不完全合适,但它可能是相关的。也许事情可以通过修改链接顺序来解决。

于 2009-11-18T20:34:39.677 回答