error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMT.
2012-10-16 13:30
387 查看
环境:在非MFC程序(使用standard windows library)中,添加MFC支持,静态链接MFC库。
发生以下错误:
问题产生原因,CRT库和MFC库链接时顺序有误:
CRT 库对 new、delete 和 DllMain 函数使用弱外部链接。MFC 库也包含 new、delete 和 DllMain 函数。这些函数要求先链接 MFC 库,然后再链接 CRT 库。
当 C 运行时 (CRT) 库和 Microsoft 基础类 (MFC) 库的链接顺序有误时,可能会出现以下 LNK2005 错误。
具体解决方法:(另一种解决方法参见最后链接,本人未测试)
在vs2005项目设置中【Linker】-【input】-【additional dependencies】追击nafxcw.lib,libcmt.lib,Debug下,追加uafxcwd.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。
接下来再次编译,还是出现以下编译出错:
解决方法:
到C++设置页中,看到Preprocessor Definitions编辑框中同时存在_USRDLL和_AFXDLL, 删除_USRDLL即可
发生以下错误:
问题产生原因,CRT库和MFC库链接时顺序有误:
CRT 库对 new、delete 和 DllMain 函数使用弱外部链接。MFC 库也包含 new、delete 和 DllMain 函数。这些函数要求先链接 MFC 库,然后再链接 CRT 库。
当 C 运行时 (CRT) 库和 Microsoft 基础类 (MFC) 库的链接顺序有误时,可能会出现以下 LNK2005 错误。
具体解决方法:(另一种解决方法参见最后链接,本人未测试)
在vs2005项目设置中【Linker】-【input】-【additional dependencies】追击nafxcw.lib,libcmt.lib,Debug下,追加uafxcwd.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。
接下来再次编译,还是出现以下编译出错:
>nafxcwd.lib(dllmodul.obj) : error LNK2005: _DllMain@12 已经在 CTXGina.obj 中定义
解决方法:
到C++设置页中,看到Preprocessor Definitions编辑框中同时存在_USRDLL和_AFXDLL, 删除_USRDLL即可
相关文章推荐
- error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMT.
- error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMT.
- VC编译错误:uafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) 已经在 LIBCMT.lib(new.obj
- error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMT.
- error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMT.lib(new.obj)链接错误!
- 调试错误的解决:error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) 已经在 LIBCMT.lib(ne
- error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMT.
- uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operatornew(unsigned int)" (??2@YAPAXI@Z) a
- nafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
- error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMT
- 调试错误的解决:error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) 已经在 LIBCMT.lib(ne
- (转+原)VC编译错误:uafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) 已经在 LIBCMT.lib(new.obj) 中定义
- nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
- error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMT.lib(new.obj)链接错误!
- error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMT.lib(new.obj)链接错误!
- Solve Error: nafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) already defined in libcpmt.lib(newaop.obj)
- 调试错误的解决:error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) 已经在 LIBCMT.lib(new
- uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
- 调试错误的解决:error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) 已经在 LIBCMT.lib(new.obj) 中定义
- VC编译错误:uafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPA