简体   繁体   中英

Link Errors With Visual Studio 2008

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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