码迷,mamicode.com
首页 > 其他好文 > 详细

error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) 已经在 LIBCMTD.lib(new.obj) 中

时间:2015-05-31 09:07:48      阅读:1106      评论:0      收藏:0      [点我收藏+]

标签:new   error   物理地址   int   代码   

在编译文章:
使用GetAdaptersAddresses函数获取物理MAC地址中的代码时,出现以下错误:
错误 1 error LNK2005: “void * __cdecl operator new(unsigned int)” (??2@YAPAXI@Z) 已经在 LIBCMTD.lib(new.obj) 中定义 F:\CcProjects\获取网卡物理地址MAC地址\获取网卡物理地址MAC地址\uafxcwd.lib(afxmem.obj) 获取网卡物理地址MAC地址

环境:Windows7+VS2010

  环境:在非MFC程序(使用standard windows library)中,添加MFC支持,静态链接MFC库。

  发生以下错误:

uafxcw.lib(afxmem.obj) : error LNK2005: “void * __cdecl operator new(unsigned int)” (??2@YAPAXI@Z) already defined in LIBCMT.lib(new.obj)
uafxcw.lib(afxmem.obj) : error LNK2005: “void __cdecl operator delete(void *)” (??3@YAXPAX@Z) already defined in LIBCMT.lib(delete.obj)
uafxcw.lib(afxmem.obj) : error LNK2005: “void * __cdecl operator new[](unsigned int)” (??_U@YAPAXI@Z) already defined in LIBCMT.lib(new2.obj)

问题产生原因,CRT库和MFC库链接时顺序有误:

The CRT libraries use weak external linkage for the new, delete, and DllMain functions. The MFC libraries also contain new,   delete, and DllMain functions. These functions require the MFC libraries to be linked before the CRT library is linked.

  具体解决方法:(另一种解决方法参见最后链接,本人未测试)

  在vs2010项目设置中【Linker】-【input】-【additional dependencies】追击nafxcw.lib,libcmt.lib,Debug下,追加Nafxcwd.lib,libcmtd.lib。

  再次编译通过,但出现

  LINK : warning LNK4098: defaultlib ‘uafxcw.lib’ conflicts with use of other libs; use /NODEFAULTLIB:library

  在【Linker】-【input】-【Ignore specific library】中追加uafxcw.lib或Debugg版本的uafxcwd.lib。

操作方法如下图:
在解决方案资源管理器中选中对应的项目
技术分享
点击项目菜单》属性,或者是直接在项目上单击鼠标右键》属性
技术分享
展开配置属性》链接器,选中输入,点击附加依赖项右侧的下拉框,在弹出的菜单中点击编辑
技术分享
输入附加依赖项,点击确定。
技术分享

error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) 已经在 LIBCMTD.lib(new.obj) 中

标签:new   error   物理地址   int   代码   

原文地址:http://blog.csdn.net/testcs_dn/article/details/46284967

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!