error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMT....

  环境:在非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.

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

  在vs2005项目设置中【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。

 

详细请参考:

http://support.microsoft.com/default.aspx?scid=kb;en-us;q148652

http://www.codeguru.com/forum/archive/index.php/t-330203.html

转载于:https://www.cnblogs.com/huangyong9527/archive/2010/09/28/1837444.html

1>Misc.obj : error LNK2001: 无法解析的外部符号 "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z) 21:13:14:191 1>AiManager.obj : error LNK2001: 无法解析的外部符号 "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z) 21:13:14:191 1>CBuffManager.obj : error LNK2001: 无法解析的外部符号 "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z) 21:13:14:191 1>CObject.obj : error LNK2001: 无法解析的外部符号 "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z) 21:13:14:191 1>dllmain.obj : error LNK2001: 无法解析的外部符号 "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z) 21:13:14:191 1>Misc.obj : error LNK2001: 无法解析的外部符号 atexit 21:13:14:191 1>ShellCode.obj : error LNK2001: 无法解析的外部符号 atexit 21:13:14:191 1>AiManager.obj : error LNK2001: 无法解析的外部符号 atexit 21:13:14:191 1>CBuffManager.obj : error LNK2001: 无法解析的外部符号 atexit 21:13:14:191 1>CObject.obj : error LNK2001: 无法解析的外部符号 atexit 21:13:14:191 1>dllmain.obj : error LNK2001: 无法解析的外部符号 atexit 21:13:14:191 1>CBuffManager.obj : error LNK2001: 无法解析的外部符号 _fltused 21:13:14:191 1>dllmain.obj : error LNK2001: 无法解析的外部符号 _fltused 21:13:14:203 1>Misc.obj : error LNK2001: 无法解析的外部符号 _fltused 21:13:14:203 1>Vector.obj : error LNK2001: 无法解析的外部符号 _fltused 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 "void * __cdecl operator new(unsigned __int64)" (??2@YAPEAX_K@Z) 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 "void * __cdecl operator new[](unsigned __int64)" (??_U@YAPEAX_K@Z) 21:13:14:203 1>ShellCode.obj : error LNK2001: 无法解析的外部符号 "void * __cdecl operator new[](unsigned __int64)" (??_U@YAPEAX_K@Z) 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 "void __cdecl operator delete[](void *)" (??_V@YAXPEAX@Z) 21:13:14:203 1>ShellCode.obj : error LNK2001: 无法解析的外部符号 "void __cdecl operator delete[](void *)" (??_V@YAXPEAX@Z) 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 _Init_thread_header 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 _Init_thread_footer 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 __imp_GetAsyncKeyState 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 __imp_GetForegroundWindow 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error@std@@YAXPEBD@Z) 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 __chkstk 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 _Init_thread_epoch 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) void (__cdecl* std::_Raise_handler)(class stdext::exception const &)" (__imp_?_Raise_handler@std@@3P6AXAEBVexception@stdext@@@ZEA) 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 "const type_info::`vftable'" (??_7type_info@@6B@) 21:13:14:203 1>dllmain.obj : error LNK2001: 无法解析的外部符号 _tls_index 21:13:14:203 1>D:\WeGameApps\英雄联盟\Game\hid.dll : fatal error LNK1120: 16 个无法解析的外部命令
最新发布
08-08
<think>我们正在处理一个关于Qt编程中链接错误的问题。用户在使用QSerialPortInfo时遇到了LNK2019错误,具体是无法解析的外部符号__imp_??1QSerialPortInfo@@QEAA@XZ。这个符号是QSerialPortInfo类的析构函数。根据经验,这种错误通常是由于项目配置中缺少必要的库链接引起的。 回顾引用内容,用户之前可能尝试过解决类似问题(如QtMultimedia模块的链接问题),但未成功。因此,我们需要确保用户正确链接了QtSerialPort模块。 步骤: 1. 确认在.pro文件中添加了serialport模块:QT += serialport 2. 确保代码中包含了正确的头文件:<QSerialPortInfo> 3. 检查Qt安装目录下是否有对应的库文件(如Qt5SerialPort.lib或Qt6SerialPort.lib) 4. 在构建系统中链接相应的库 另外,根据错误信息中的符号名称(带有__imp_前缀),这通常表示该符号来自动态链接库(DLL)。因此,还需要确保程序运行时能够找到对应的DLL文件。 如果用户使用的是CMake,则需要在CMakeLists.txt中添加对QtSerialPort的依赖。 由于用户之前可能已经尝试过类似方法,我们需要更详细地检查配置。 生成相关问题: 1. 您是否在项目文件(如.pro文件或CMakeLists.txt)中添加了serialport模块? 2. 您的Qt安装是否包含了SerialPort模块?您是否使用官方安装程序安装的? 3. 您是否在代码中包含了正确的头文件?例如:#include <QSerialPortInfo> 4. 您能否检查一下构建目录中是否有Qt5SerialPort.lib(或Qt6SerialPort.lib)?链接器是否能够找到它? 5. 您是否在项目设置中正确配置了库的路径? 注意:由于用户的问题描述中提到了QSerialPortInfo,我们应专注于QtSerialPort模块的配置。 但是,根据用户提供的引用,他们之前可能还遇到了其他模块的类似问题(如QtMultimedia),因此需要确保用户没有混淆模块的配置。 另外,引用[3]中提到了析构函数未解析的问题,与用户当前的问题类似(都是析构函数无法解析),所以解决方案应该是类似的:确保链接正确的库。 因此,回答将围绕如何正确链接QtSerialPort模块展开。</think>### 解决 QSerialPortInfo 链接错误 LNK2019 当遇到 `LNK2019: 无法解析的外部符号 __imp_??1QSerialPortInfo@@QEAA@XZ` 错误时,表明链接器无法找到 `QSerialPortInfo` 类的析构函数实现。这通常由以下原因引起: #### 解决方法: 1. **添加 QtSerialPort 模块依赖** 在项目配置文件(`.pro` 或 `CMakeLists.txt`)中明确添加 `serialport` 模块: ```qmake QT += core serialport # 在 .pro 文件中添加 ``` ```cmake find_package(Qt6 COMPONENTS Core SerialPort REQUIRED) # CMake 配置 target_link_libraries(your_target PRIVATE Qt6::SerialPort) ``` 2. **检查头文件包含** 确保代码中正确包含头文件: ```cpp #include <QSerialPortInfo> // 正确形式(无子模块路径) ``` 3. **验证库文件链接** - 检查构建目录是否生成了 `Qt5SerialPort.lib`/`Qt6SerialPort.lib`(Windows)或 `.a` 文件(Linux/macOS) - 确认链接器路径包含 Qt 的库目录(如 `C:\Qt\6.5.0\msvc2019_64\lib`) 4. **清理并重新构建** 删除 `build` 目录和 `Makefile` 等缓存文件后完整重建项目。 5. **检查 Qt 安装完整性** 通过 Qt Maintenance Tool 确认 `QtSerialPort` 组件已安装: ``` [安装选项] → [选择组件] → 勾选 "Qt Serial Port" ``` #### 根本原因: - 符号 `__imp_??1QSerialPortInfo@@QEAA@XZ` 是 `QSerialPortInfo` 析构函数的修饰名,未链接 `QtSerialPort` 库时无法解析该符号[^1]。 - Qt 模块化设计要求显式声明依赖,否则链接器会跳过相关库的加载[^2]。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值