nafxcwd.lib(afxmem.obj) : error LNK2005
来源:互联网 发布:数据建模的方法 编辑:程序博客网 时间:2024/05/16 19:30
(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
清除项目。重新编译。搞定
方法二
:
解决方案二:找到并纠正出现问题的模块
要查看当前的库链接顺序,请按照下列步骤操作:
- 在“项目”菜单上,单击“设置”。
- 在“项目设置”对话框的“以下项目的设置”视图中,单击以选中出现链接错误的项目配置。
- 在“链接”选项卡上的“项目选项”框中键入 /verbose:lib。
- 重新生成项目。在链接过程中,这些库将在输出窗口中列出。
方法3
可能上面方法二的那个也要加上 也可能不加
项目--属性 ---连接器---命令行 输入: /FORCE:MULTIPLE
- 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常见错误:>nafxcwd.lib(afxmem.obj) : error LNK2005
- 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 delete(void *)" (??3@YAXPAX@Z)
- 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 new(unsigned int)" (??2@YAPAXI@Z)
- 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
- 链接错误nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in libcpd
- VS调试出错: uafxcw.lib(afxmem.obj) : error LNK2005
- nafxcwd.lib和afxmem.obj的冲突
- nafxcwd.lib(dllmodul.obj) : error LNK2005: _DllMain@12
- "nafxcwd.lib(dllmodul.obj) : error LNK2005: _DllMain@12..."错误!
- 为什么选择firefox os
- 97 Things Every Programmer Should Know (oreilly.com)
- 特殊方法求1~n的和
- 题目86:胜利大逃亡
- 如何解决在DOS编译java类时出现的“错误: 编码GBK的不可映射字符”
- nafxcwd.lib(afxmem.obj) : error LNK2005
- Android ListView嵌套Button,Button事件覆盖item事件解决办法
- MyEclipse中web开发修改类文件和配置文件不重启服务器的方法
- 简洁的Bash编程技巧
- MySQL 优化综述专题
- 女儿在老家半年
- 调试Release发布版程序的Crash错误(Win7)
- 玩转java之io的键盘录入和文件拷贝
- 看"陈洁如的悲情人生"有感