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。

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

目录
相关文章
|
9月前
|
TensorFlow 算法框架/工具
Tensorflow error(二):x and y must have the same dtype, got tf.float32 != tf.int32
本文讨论了TensorFlow中的一个常见错误,即在计算过程中,变量的数据类型(dtype)不一致导致的错误,并通过使用`tf.cast`函数来解决这个问题。
94 0
error C2040: ‘n‘ : ‘int [1000]‘ differs in levels of indirection from ‘int ‘
error C2040: ‘n‘ : ‘int [1000]‘ differs in levels of indirection from ‘int ‘
180 0
|
关系型数据库 MySQL C++
类型收窄 error C2397: conversion from ‘const int‘ to ‘char‘ requires a narrowing conversion
类型收窄 error C2397: conversion from ‘const int‘ to ‘char‘ requires a narrowing conversion
346 0
|
关系型数据库 MySQL C++
Error:E0415 no suitable constructor exists to convert from “int“ to “Rational“
Error:E0415 no suitable constructor exists to convert from “int“ to “Rational“
228 0
|
Linux Windows
编译OpenJDK8-u302出错:error C3861: “INT64_C”: 找不到标识符
编译OpenJDK8-u302出错:error C3861: “INT64_C”: 找不到标识符
158 0
解决办法:error: unknown type name ‘__int64‘
解决办法:error: unknown type name ‘__int64‘
564 0
__cdecl operator new(unsigned int)" (??2@YAPAXI@Z) 已经在 LIBCMT.lib(new.obj) 中定义
__cdecl operator new(unsigned int)" (??2@YAPAXI@Z) 已经在 LIBCMT.lib(new.obj) 中定义
126 0
__cdecl operator new(unsigned int)" (??2@YAPAXI@Z) 已经在 LIBCMT.lib(new.obj) 中定义
解决办法:error LNK2005: "void * __cdecl operator new(unsigned int)" 已经在 LIBCMTD.lib(new.obj) 中定义
解决办法:error LNK2005: "void * __cdecl operator new(unsigned int)" 已经在 LIBCMTD.lib(new.obj) 中定义
436 0
|
4月前
|
存储 C语言 Python
[oeasy]python077_int类型怎么用_整数运算_integer_进制转化_int类
本文主要讲解了Python中`int`类型的应用与特性。首先回顾了`int`词根的溯源,探讨了整型变量的概念及命名规则(如匈牙利命名法)。接着分析了整型变量在内存中的存储位置和地址,并通过`type()`和`id()`函数验证其类型和地址。还介绍了整型变量的运算功能,以及如何通过`int()`函数将字符串转化为整数,支持不同进制间的转换(如二进制转十进制)。此外,文章提及了关键字`del`的使用场景,对比了Python与C语言中`int`的区别,并总结了整型与字符串类型的差异,为后续深入学习奠定基础。
68 1

热门文章

最新文章