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

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

在编译文章:
使用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。

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

目录
相关文章
|
5月前
|
TensorFlow 算法框架/工具
Tensorflow error(二):x and y must have the same dtype, got tf.float32 != tf.int32
本文讨论了TensorFlow中的一个常见错误,即在计算过程中,变量的数据类型(dtype)不一致导致的错误,并通过使用`tf.cast`函数来解决这个问题。
50 0
Operator ‘==‘ cannot be applied to ‘int‘, ‘null‘
Operator ‘==‘ cannot be applied to ‘int‘, ‘null‘
|
10月前
|
SQL 关系型数据库 MySQL
unsigned int 虽然mysql支持,但是不建议使用,因为可能在未来某个版本删除
unsigned int 虽然mysql支持,但是不建议使用,因为可能在未来某个版本删除
68 2
|
10月前
|
编译器 C++
C++_int负数转unsigned
C++_int负数转unsigned
120 0
|
编译器
unsigned long int 和 unsigned long一样吗?
unsigned 代表的是无符号的整形数
343 0
|
10月前
|
存储 人工智能 编译器
learn_C_deep_5 (温故知新、sigend char a = -128的深度理解、unsigned int类型的写法规范)
learn_C_deep_5 (温故知新、sigend char a = -128的深度理解、unsigned int类型的写法规范)
103 0
|
10月前
|
存储 编译器 程序员
learn_C_deep_4 (类型和变量命名、sizeof(int) *p表示什么意思、原码、反码和补码的概念、计算机中数据计算时,为什么要转为二级制、unsigned和signed关键字)
learn_C_deep_4 (类型和变量命名、sizeof(int) *p表示什么意思、原码、反码和补码的概念、计算机中数据计算时,为什么要转为二级制、unsigned和signed关键字)
|
10月前
|
存储 C语言
学习总结(位操作符;循环输入的三种方式;交换两个变量值的三种方法;打印数字对应的二进制;unsigned int 与int 的区别;改变特定位数0/1;&&和||的连续操作(与前置,后置结合))
学习总结(位操作符;循环输入的三种方式;交换两个变量值的三种方法;打印数字对应的二进制;unsigned int 与int 的区别;改变特定位数0/1;&&和||的连续操作(与前置,后置结合))
96 0
|
存储 小程序 程序员
8k字详解整型(int)/字符型(char)/浮点型(float)/有符号(signed)/无符号(unsigned)数据在内存中的存储【程序员内功修炼/C语言】
8k字详解整型(int)/字符型(char)/浮点型(float)/有符号(signed)/无符号(unsigned)数据在内存中的存储【程序员内功修炼/C语言】
258 0

热门文章

最新文章