VC常见错误:>nafxcwd.lib(afxmem.obj) : error LNK2005
来源:互联网 发布:mac系统清理工具 免费 编辑:程序博客网 时间:2024/05/29 19:07
(1)错误案例:在写日志程序中出现,工程是MFC程序(注:win32控制台应用程序,不会出现这种错误,当然是不支持MFC库的那种)
(2)错误原因:如下能看出一点眉目,重定义了.在使用***.obj时,已经在***.lib库中定义了.
摘抄:
上网搜了下,是CRT库与MFC库的冲突,解决方法是:让程序先链接Nafxcwd.lib,然后再链接Libcmtd.lib
you've got to change the order inwhich the libraries are linked. This is a bit tricky, since the library are linked automatically, without you explicitly specifying them.
So, first step, tell the linker to ignore the implicit libraries: Project/Setting/Linker, Input Tab, and put "Nafxcwd.lib Libcmtd.lib" in the "Libraries to Ignore" box.
Next, on the same page, in the Object/library Modules box, put the same to libraries. (in you still get the same error, try reversing them on this line)
可以从错误信息里看到,操作符new,delete,delete[]已经在LIBCMTD.lib中定义了,这跟C编译时使用的默认库与MFC运行时的默认编译库编译时链接顺序有关,我们可以手动的改变两个库的编译顺序就能解决这个定义冲突问题。
(3)错误现场:
1>正在链接...
1>nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" () 已经在 LIBCMTD.lib(new.obj) 中定义
1>nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" () 已经在 LIBCMTD.lib(dbgdel.obj) 中定义
1>nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" () 已经在 libcpmtd.lib(newaop.obj) 中定义
1>nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" () 已经在 LIBCMTD.lib(delete2.obj) 中定义
1>C:\Documents and Settings\Administrator\桌面\多线程写日志怎样写\写日志1\Debug\写日志1.exe : fatal error LNK1169: 找到一个或多个多重定义的符号
(4)错误解决办法:
中文
项目--属性 ---连接器---输入
附加依赖项 空格Nafxcwd.lib Libcmtd.lib
忽略指定库 空格Nafxcwd.lib Libcmtd.lib
清除项目。重新编译。搞定
- VC常见错误:>nafxcwd.lib(afxmem.obj) : error LNK2005
- nafxcwd.lib(afxmem.obj) : error LNK2005
- nafxcwd.lib(afxmem.obj) error lnk2005
- nafxcwd.lib(afxmem.obj) : error LNK2005
- nafxcwd.lib(afxmem.obj) : error LNK2005
- VC++常规错误之17:1>nafxcwd.lib(afxmem.obj) : error LNK2005
- VC++常规错误之17:1>nafxcwd.lib(afxmem.obj) : error LNK2005
- 链接错误nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z)
- 链接错误nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in libcpd
- nafxcwd.lib(afxmem.obj) :error LNK2005:"void * __cdecl operator new(unsigned int)"
- nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" already defined
- nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
- "nafxcwd.lib(dllmodul.obj) : error LNK2005: _DllMain@12..."错误!
- nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" already defined in LIBCMTD.lib(new.obj)
- uafxcwd.lib(afxmem.obj) : error LNK2005
- VC++编译错误: Nafxcwd.lib(dllmodul.obj) : error LNK2005: _DllMain@12已经在dllmain.obj 中定义
- uafxcwd.lib(afxmem.obj) : error LNK2005: 已经在 LIBCMTD.lib(new.obj) 中定义错误解决方案
- uafxcwd.lib(afxmem.obj) : error LNK2005: 已经在 LIBCMTD.lib(new.obj) 中定义错误解决方案
- Uva 11729 - Commando War ( 贪心 + 水 )
- 多线程编程基础知识
- 关于protobuf javascript的版本
- Hadoop作业提交分析(一)
- 字符数组之间赋值
- VC常见错误:>nafxcwd.lib(afxmem.obj) : error LNK2005
- DP之花店橱窗布置
- RMAN - 备份与恢复实践 之二
- asp.net mvc 模板生成word文档
- SIP协议详解(中文)-3
- C# InputManager示例
- 整数划分(三)
- Android使用"中国天气网"API数据通过城市名称获取天气情况
- java ssh 框架下 利用junit4 spring-test进行单元测试