Evil Error Link 2005 problem on release configuration; Debug config works great!?!

Hey everyone, I have the following issue: I am not able to build a release version of my app, although building a debug one works great.

So I looked up error 2005 and it said to put libcmt.lib & nafxcw.lib in the ignore directive... WHICH i DID

(results of ignoring libcmt.lib & nafcw.lib, but still adding them to additioanl linker depdendcies)
Here a choice selection of the more than 200 errors:
LIBCMT.lib(invarg.obj) : error LNK2005: __initp_misc_invarg already defined in Libcmtd.lib(invarg.obj)
LIBCMT.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in Libcmtd.lib(invarg.obj)
LIBCMT.lib(invarg.obj) : error LNK2005: __set_invalid_parameter_handler already defined in Libcmtd.lib(invarg.obj)
LIBCMT.lib(invarg.obj) : error LNK2005: __get_invalid_parameter_handler already defined in Libcmtd.lib(invarg.obj)

(results of ignoring libcmt.lib & nafcw.lib, but NOT including them to additional linker depencies)
nafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" ( 2@YAPAXI@Z) already defined in LIBCMT.lib(new.obj)
nafxcw.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" ( 3@YAXPAX@Z) already defined in LIBCMT.lib(delete.obj)
nafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" ( _U@YAPAXI@Z) already defined in LIBCMT.lib(new2.obj)
nafxcw.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" ( _V@YAXPAX@Z) already defined in LIBCMT.lib(delete2.obj)

And finally, the library settings that work great for the debug verison:
ADDITIONAL LINKDER DEPENDICIES: user32.lib odbc32.lib odbccp32.lib scrnsave.lib comctl32.lib kernel32.lib gdi32.lib Nafxcwd.lib Libcmtd.lib Advapi32.lib
IGNORE LIBRARIES: Nafxcwd.lib Libcmtd.lib


Answer this question

Evil Error Link 2005 problem on release configuration; Debug config works great!?!

  • Loren Jensen

    I know this post is very late, but I just got the same thing in VC6 and it was caused by a project settings error.

    On the Project - Settings - General tab, you should see: Use MFC in a Shared DLL.

    Mysteriously, this setting was blank. Anyway, clicking on the drop-down arrow brought the 'Use MFC in a shared DLL' into view and the problem vanished.

    Maybe this occurs in VS2005 too.

  • virenkar

    I do in fact have the same libraries in both debug & release builds.... is this a bad move

    Next, I'm not sure whata you mean by "You've added the non-debug version and you're still getting clashes".

  • Sync_Austin

    __initp_misc_invarg already defined in Libcmtd.lib(invarg.obj)

    I'd say this means that you have libcmtd.lib included in both release and debug builds, so you've added the non-debug version and you're getting clashes.



  • Reeves

    What i mean is, the one that ends in D should link against the debug version, the one without the D should link to the release. They are both the same library, one is built in debug, the other in release. That's why you're getting clashes, you have two identical libraries that are trying to export the same functions, one is a debug version and the other release.



  • IBRAHIM ERSOY

    Thanks for the tip. So I took the 'd' off both, but still no luck.

    Having LIBCMT.lib and nafxcw.lib both in the ignore library box
    - or having them both in the ignore box and adding them on input libaries both produced the same result:
    Linking...
    nafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" ( 2@YAPAXI@Z) already defined in LIBCMT.lib(new.obj)
    nafxcw.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" ( 3@YAXPAX@Z) already defined in LIBCMT.lib(delete.obj)
    nafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" ( _U@YAPAXI@Z) already defined in LIBCMT.lib(new2.obj)
    nafxcw.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" ( _V@YAXPAX@Z) already defined in LIBCMT.lib(delete2.obj)

    Perhaps it should be noted in one of my files I'm #include <new> .... because I thought I needed to.... Perhaps this is what is messing me up I tried commetning it out, but I still got this error.

  • Galex Yen - MSFT

    This post is very late as well. I got this error trying to build some code I downloaded from codeproject.com. VS2003 converted the downloaded project and left me with the link errors. Changing from "MFC Statically linked" to "Use MFC in a Shared DLL" made the problem go away, but I wanted static linking. Googling around I found another post with this information:

    I think you have "found" the following problem:
    KB-article Q148652
    http://support.microsoft.com/default.aspx scid=kb;en-us;148652

    -> (exclude and) include the run-time libraries in correct order

    For me, since the code I downloaded originated in VS6, per the article above the solution was as simple as making sure each .cpp file had #include "stdafx.h" as the first line. One file did not. This apparently forces the proper order.



  • Evil Error Link 2005 problem on release configuration; Debug config works great!?!