none
How to get rid of link error: LNK2005 RRS feed

  • Question

  • Hi,
    I am using VC 2005 version.
    I am having these linking error:
    1>nafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMT.lib(new.obj)
    1>nafxcw.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in LIBCMT.lib(delete.obj)
    1>nafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) already defined in LIBCMT.lib(new2.obj)
    1>nafxcw.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" (??_V@YAXPAX@Z) already defined in LIBCMT.lib(delete2.obj)

    Does any know how to fix this issue?

    I am only having this error in release build but not in debug build.
    Sunday, September 13, 2009 8:37 AM

Answers

  • But did you compare Debug and Release builds (since you are talking about all your libraries, not your release types) as nobugz told you. Also, make sure that you are not using debug libraries in release builds, this will break up the code as well.
    Geert van Horrik - CatenaLogic
    Visit my blog: http://blog.catenalogic.com

    Looking for a way to deploy your updates to all your clients? Try Updater!
    Monday, September 14, 2009 5:15 AM

All replies

  • Make sure that you are linking to the correct libraries. You can check this via Right click on project -> Properties -> Linker -> Input -> Additional Dependencies.
    Geert van Horrik - CatenaLogic
    Visit my blog: http://blog.catenalogic.com

    Looking for a way to deploy your updates to all your clients? Try Updater!
    Sunday, September 13, 2009 9:00 AM
  • You are mixing the DLL version of MFC with the static version of the CRT.  Depending on which one you really want, either change General, Use of MFC or C/C++, Code Generation, Runtime Library.  Make the Release setting the same as the Debug setting.

    Hans Passant.
    Sunday, September 13, 2009 12:17 PM
    Moderator
  • I am pretty sure I did.  I am using static MFC for all my libraries.   I also checked to make sure all my libraries used the same link options. 
    Monday, September 14, 2009 1:20 AM
  • But did you compare Debug and Release builds (since you are talking about all your libraries, not your release types) as nobugz told you. Also, make sure that you are not using debug libraries in release builds, this will break up the code as well.
    Geert van Horrik - CatenaLogic
    Visit my blog: http://blog.catenalogic.com

    Looking for a way to deploy your updates to all your clients? Try Updater!
    Monday, September 14, 2009 5:15 AM
  • Hi WestRace,

    Since it is only your release build experiencing issues, I suggest you check which libraries are referenced in your debug build and ensure the same libraries are referenced in the release build, exchanging the release version library for the debug version library as applicable. 
    Wednesday, September 16, 2009 2:25 AM