Visual Studio 2008 的链接错误

发布于 2024-11-26 23:02:18 字数 2877 浏览 1 评论 0原文

我昨天刚从 2005 升级到 Visual Studio 2008。好吧,我正在尝试利用一些新类(特别是 CFrameWndEx),但出现错误。声明一个 CFrameWndEx 子类,然后将 afxcmdiframewndex.h 添加到 stdafx.h 只会给我一个错误。看似无害的一个。我刚刚收到“COleDropTarget 基类未定义”的错误。好的,简单的修复,将 afxole.h 添加到我的包含中,一切都会好起来的。但当我这样做之后,一切就都崩溃了。在链接之前,输出中的所有内容都很好:

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

使用 /NODEFAULTLIB 来摆脱 msvcrtd.lib 和 LIBCMT 只会导致更多问题的混乱。我认为解决此问题的一种方法是找到与 msvcrtd.lib 和 LIBCMT 冲突的库,但我该如何去做呢?

以前有人见过这个问题吗?这似乎与微软代码有冲突,但也有可能是我的代码。任何帮助将不胜感激。

提前致谢。

I just upgraded to Visual Studio 2008 from 2005 yesterday. Well, I'm trying to take advantage of some of the new classes (specifically CFrameWndEx) and I'm getting errors. Declaring a CFrameWndEx child class and then adding afxcmdiframewndex.h to stdafx.h gives me only one error. A seemingly harmless one at that. I just get the error that "COleDropTarget base class undefined". OK, simple fix, add afxole.h to my includes and it'll all be good. 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. 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?

Has anybody seen this problem before? It seems like a conflict with Microsoft code, but it's possible that it could be my code. Any help would be much appreciated.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怎樣才叫好 2024-12-03 23:02:18

您的问题是 msvcrtd.lib 与 LIBCMT.lib 冲突。它们不应该同时使用。编译多线程动态链接调试运行时 (/MDd) 时使用 msvcrtd.lib 库,而编译多线程静态链接非调试运行时 (/MT) 时使用 LIBCMT。请参阅此处了解一些背景信息。

如果未指定开关,则默认使用 LIBCMT。

可能值得检查“配置属性”| C/C++ | “代码生成” | “运行时库”设置,以确认其设置为 /MD(用于发布版本)和 /MDd(用于调试版本)。您需要检查项目的设置并检查项目中的每个 cpp 文件,因为各个文件可能有不同的设置。

老实说,如果开关设置错误,我什至在包含 afxole.h 之前就预计问题会显现出来,并且我预计 afxver.h 会生成一个错误,要求您使用 /MD 开关,因此问题可能比开关设置错误更微妙。

更新:我删除了对 /ML 开关的引用,那是 Visual Studio 2003 而不是 Visual Studio 2005。

更新:如果您添加了 <,请再考虑一下这个问题code>afxframewndex.h 那么您不需要显式包含 afxole.h 因为它应该为您包含在内。

如果您打开 /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

你需要摆脱 afxole.h 的显式 #include 并找出为什么 COleDropTarget 基类未定义,尽管afxframewindex.h 被包含在内。

Your problem is that msvcrtd.lib is conflicting with 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). See here for some background.

LIBCMT is the default used if no switch is specified.

It might be worth checking the "Configuration properties" | C/C++ | "Code Generation" | "Runtime Library" setting to confirm that it is set to /MD for Release builds and /MDd for debug builds. 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.

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.

Update: I took out the reference to /ML switch, that was Visual Studio 2003 not 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.

If you turn on /showIncludes and compile your program the Output window should show something like this...

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文