简体   繁体   English

使用Visual Studio 2008链接错误

[英]Link Errors With Visual Studio 2008

I just upgraded to Visual Studio 2008 from 2005 yesterday. 我昨天才从2005年升级到Visual Studio 2008。 Well, I'm trying to take advantage of some of the new classes (specifically CFrameWndEx) and I'm getting errors. 好吧,我试图利用某些新类(特别是CFrameWndEx),但遇到了错误。 Declaring a CFrameWndEx child class and then adding afxcmdiframewndex.h to stdafx.h gives me only one error. 声明一个CFrameWndEx子类,然后将afxcmdiframewndex.h添加到stdafx.h中,只会给我一个错误。 A seemingly harmless one at that. 那个似乎无害。 I just get the error that "COleDropTarget base class undefined". 我只是得到“ COleDropTarget基类未定义”的错误。 OK, simple fix, add afxole.h to my includes and it'll all be good. 好,简单的修复,将afxole.h添加到我的include中,一切都会很好。 But after I do that is when all hell breaks loose. 但是,在那之后,一切都破灭了。 Everything in the output is good until linking: 在链接之前,输出中的所有内容都很好:

1>LIBCMT.lib(sprintf.obj) : error LNK2005: _sprintf already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(tidtable.obj) : error LNK2005: __encode_pointer already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(tidtable.obj) : error LNK2005: __decode_pointer already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(setlocal.obj) : error LNK2005: __configthreadlocale already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __exit already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __cexit already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(mlock.obj) : error LNK2005: __unlock already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(mlock.obj) : error LNK2005: __lock already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(strftime.obj) : error LNK2005: _strftime already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in msvcrtd.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in msvcrtd.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in msvcrtd.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrtd.lib(cinitexe.obj)
1>LIBCMT.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in msvcrtd.lib(MSVCR90D.dll)
1>LIBCMT.lib(errmode.obj) : error LNK2005: ___set_app_type already defined in msvcrtd.lib(MSVCR90D.dll)
1>msvcrtd.lib(MSVCR90D.dll) : error LNK2005: __setmbcp already defined in LIBCMT.lib(mbctype.obj)
1>LINK : warning LNK4098: defaultlib 'msvcrtd.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library

And using /NODEFAULTLIB to get rid of msvcrtd.lib and LIBCMT just caused a whole mess load of more problems. 使用/ NODEFAULTLIB摆脱msvcrtd.lib和LIBCMT只会造成更多问题的混乱。 I would assume that one way of fixing this would be to find the libraries conflicting with msvcrtd.lib and LIBCMT, but how do I go about doing this? 我认为解决此问题的一种方法是找到与msvcrtd.lib和LIBCMT冲突的库,但是我该怎么做呢?

Has anybody seen this problem before? 有人看过这个问题吗? It seems like a conflict with Microsoft code, but it's possible that it could be my code. 似乎与Microsoft代码发生冲突,但有可能是我的代码。 Any help would be much appreciated. 任何帮助将非常感激。

Thanks in advance. 提前致谢。

Your problem is that msvcrtd.lib is conflicting with LIBCMT.lib. 您的问题是msvcrtd.lib与LIBCMT.lib冲突。 They shouldn't both be used. 它们不应该同时使用。 The msvcrtd.lib library is used when compiling for multi-thread dynamic linking debug run time (/MDd) while LIBCMT is used when compiling for multi-threaded static linking non-debug run time (/MT). msvcrtd.lib库在编译时用于多线程动态链接调试运行时(/ MDd),而LIBCMT在编译时用于多线程静态链接非调试运行时(/ MT)。 See here for some background. 有关某些背景,请参见此处

LIBCMT is the default used if no switch is specified. 如果未指定任何开关,则默认使用LIBCMT。

It might be worth checking the "Configuration properties" | 可能值得检查“配置属性”。 C/C++ | C / C ++ | "Code Generation" | “代码生成” | "Runtime Library" setting to confirm that it is set to /MD for Release builds and /MDd for debug builds. “运行时库”设置,以确认对于Release版本将其设置为/ MD,对于调试版本将其设置为/ MDd。 You'd need to check that setting for the project and ofr every cpp file in the project since individual files can have different settings. 您需要检查项目的设置,并检查项目中的每个cpp文件,因为单个文件可以具有不同的设置。

To be honest though, if the switch setting were wrong I'd have expected the problem to manifest itself even before you included afxole.h and I would have expected afxver.h to generate an error asking you to use the /MD switch so the problem may be more subtle than just a wrong switch setting. 不过,老实说,如果开关设置错误,我希望该问题甚至在您包含afxole.h之前就已经显现出来,并且我希望afxver.h生成一个错误,要求您使用/ MD开关,因此问题可能不仅仅在于开关设置错误。

Update : I took out the reference to /ML switch, that was Visual Studio 2003 not Visual Studio 2005. 更新 :我删除了对/ ML开关的引用,它是Visual Studio 2003而不是Visual Studio 2005。

Update : Thinking about this some more, if you've added afxframewndex.h then you should not need to explicitly include afxole.h because it should get included for you. 更新 :进一步考虑一下,如果您添加了afxframewndex.h那么您无需显式包括afxole.h因为它应该为您包括在内。

If you turn on /showIncludes and compile your program the Output window should show something like this... 如果打开/ showIncludes并编译程序,则“输出”窗口应显示以下内容...

1>Note: including file:  c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\include\afxframewndex.h
[snipped all the includes due to afxframeimpl.h and afxcontrolbarutil.h]
1>Note: including file:   c:\program files (x86)\microsoft visual studio 9.0\vc\atlmfc\include\afxpopupmenu.h
1>Note: including file:    c:\program files (x86)\microsoft visual studio 9.0\vc\atlmfc\include\afxpopupmenubar.h
1>Note: including file:     c:\program files (x86)\microsoft visual studio 9.0\vc\atlmfc\include\afxtoolbar.h
1>Note: including file:      c:\program files (x86)\microsoft visual studio 9.0\vc\atlmfc\include\afxtoolbardroptarget.h
1>Note: including file:       c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\include\afxole.h

You need to get rid of your explicit #include of afxole.h and figure out why the COleDropTarget base class is undefined despite afxframewndex.h being included. 您需要摆脱afxole.h的显式#include并弄清楚为什么尽管包含了afxframewndex.h也未定义COleDropTarget基类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM