4

我正在尝试在 Microsoft Visual Studio 2012 中编译我的 Visual C++ 项目(使用 MFC),它返回以下错误:

error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj)   
error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in LIBCMTD.lib(dbgdel.obj) 
error LNK2005: "void __cdecl operator delete[](void *)" (??_V@YAXPAX@Z) already defined in LIBCMTD.lib(delete2.obj)
error LNK1169: one or more multiply defined symbols found

所以我用谷歌搜索了一下,找到了这个页面:http: //support.microsoft.com/ ?scid= kb%3Ben-us%3B148652&x =13&y=8 我尝试了解决方案一,但“忽略库”框不存在,对象/库模块框也是如此。对于 Ignore Libraries,我找到了 Ignore specific library,但跳过第五步只会给我 17xx 错误。

我用谷歌搜索了很多,但总是回到同一个页面,如何在 Visual Studio 2012 中解决这个问题?

4

5 回答 5

2

The most likely cause of the problem is having different versions of the C runtime (multi- or single-threaded, debug- or non-debug) linked for different parts of the project. Perhaps your main executable has one runtime linked but you are linking to a library built with a different runtime. Use depends.exe to check each library that you are linking explicitly in turn to find the odd one out.

于 2012-10-16T12:50:54.663 回答
2

我解决了这个问题:我发现这是包含顺序的问题。但是,强制每个文件都包含 afx.h (properties->c/c++/advanced/force include file) 为我解决了这个问题。

于 2012-10-30T14:49:20.970 回答
2

我还发现,如果您使用 LTGC(链接时代码生成)并且您刚刚为operator newCRT 中存在的其他符号添加了自定义实现,那么您应该进行完全重建,然后增量链接器才会省略“弱引用”。即使在 VS 2015 中也是如此。

于 2016-03-29T11:13:51.953 回答
1

好的,我刚刚在将 .c 文件(编译单元)与 MFC 项目结合时处理了这个问题。.c 文件与我链接的库中的名称(编译单元)相同。我更改了文件名,链接器混乱消失了。

我尝试了上面的其他解决方案,但都没有奏效。

于 2016-03-04T01:04:20.227 回答
0

您在使用 Visual Studio 2008 或 2010 时遇到过这个问题吗?

我在 Visual Studio 2012 中看到了类似的失败:在早期版本的工具链中链接良好的代码现在提供了多个error LNK2005: "void * __cdecl operator new(unsigned __int64,void *)" (??2@YAPEAX_KPEAX@Z) already defined. 与您不同,我们没有使用 MFC。

当然,这不是您的问题的解决方案,但它可能指向 Microsoft 编译器或链接器开发中的回归错误。如果您可以验证相同的代码在 VS2010 中可以正常工作,那将倾向于确认我的诊断。

(要检查这一点,只需将解决方案中所有项目的项目属性>配置属性>常规>平台工具集从“v110”设置为“v100”,然后全部重建。假设您在同一台机器上安装了VS2010,您可以这样做这一切都没有离开VS2012。)

编辑添加:此错误已作为错误 #768788报告给 Microsoft 。

于 2012-10-26T03:30:39.360 回答