Visual Studio-在调试模式下错误LNK2005 [英] Visual Studio - error LNK2005 in debug mode

查看:467
本文介绍了Visual Studio-在调试模式下错误LNK2005的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Visual Studio 2010下将第3方代码集成到我的MFC应用程序中.
在调试"模式下,会发生以下构建错误:

I'm integrating 3rd party code into my MFC app under Visual Studio 2010.
When in Debug mode the following build error occurs:

1>LIBCMT.lib(invarg.obj) : error LNK2005: __initp_misc_invarg already defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __call_reportfault already defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __set_invalid_parameter_handler already defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __get_invalid_parameter_handler already defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: "void __cdecl _invoke_watson(unsigned short const *,unsigned short const *,unsigned short const *,unsigned int,unsigned int)" (?_invoke_watson@@YAXPBG00II@Z) already defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __invalid_parameter already defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: "void __cdecl _invalid_parameter(unsigned short const *,unsigned short const *,unsigned short const *,unsigned int,unsigned int)" (?_invalid_parameter@@YAXPBG00II@Z) already defined in libcmtd.lib(invarg.obj)
1>LIBCMT.lib(invarg.obj) : error LNK2005: ___pInvalidArgHandler already defined in libcmtd.lib(invarg.obj)
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>D:\My Documents\Dev\MyProject\MyProject\Debug\MyProject.exe : fatal error LNK1169: one or more multiply defined symbols found

使用此建议,我能够完成构建有两种方式:

Using this advice I was able to complete the build in two ways:

  • 在释放模式下
  • 在调试模式下,使用/FORCE:MULTIPLE作为附加的链接器命令行选项

在第二种情况(调试模式)下,仍然会报告许多警告.如果我还添加/NODEFAULTLIB:LIBCMT,它们中的大多数都消失了.

In the second case (Debug mode) many warnings are still reported. If I also add /NODEFAULTLIB:LIBCMT most of them are gone.

这是什么原因?
我该如何解决这个问题,而不是解决它?

What is the cause of this?
How can I solve this, instead of working around it?

推荐答案

由于某种原因,您同时链接了LIBCMT和LIBCMTD(调试版本). (通过读取每个错误行的结尾:already defined in libcmtd.lib(invarg.obj))

For some reason, you're linking against both LIBCMT and LIBCMTD (the debug version). (From reading the end of each error line: already defined in libcmtd.lib(invarg.obj))

您通过说/NODEFAULTLIB:LIBCMT来纠正正确的事情.您要链接的第三方库上的调试/发布标志是否与应用程序构建中的调试/发布模式匹配?我猜想第三方代码会以某种方式引入冗余库.

You're fixing the right thing by saying /NODEFAULTLIB:LIBCMT. Does the debug/release flag on the third-party library that you're linking against match the debug/release mode on your app build? I would guess that the third-party code is pulling in a redundant library somehow.

这篇关于Visual Studio-在调试模式下错误LNK2005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆