none
uafxcwd.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in MyTestDll.obj

    Question

  • 1>uafxcwd.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in MyTestDll.obj
    1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj)
    1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in LIBCMTD.lib(dbgdel.obj)
    1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) already defined in libcpmtd.lib(newaop.obj)
    1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" (??_V@YAXPAX@Z) already defined in LIBCMTD.lib(delete2.obj)
    

    I am getting the above errors when compiling a VS 2005 project. Use of MFC is set as "Use Standard Windows Libraries" so I am puzzled why it is trying to link to uafxcwd.lib which is an MFC library

    I've tried to create the project from scratch and added the source files/header files one by one but since there're just too many of them, I would add them in batch but in the end, I still get the above link ERRORS.

    Is there a header file that would cause visual studio to link to uafxcwd.lib ?

    What should I do to fix it?

    Is adding /FORCE:MULTIPLE into the command line of the linker a good fix?

    Wednesday, April 27, 2011 1:46 AM

Answers

  • Hi,

     

    According to my knowledge, it seems that it is a link issue in your project. The CRT libraries use weak external linkage for the new, delete, and DllMain functions. The MFC libraries also contain new, delete, and DllMain functions. These functions require the MFC libraries to be linked before the CRT library is linked. There are two ways to resolve this problem. The first solution involves forcing the linker to link the libraries in the correct order. The second solution allows you to find the module that is causing the problem and to correct it.

     

    Here is the detail information about LNK 2005;

    1. http://support.microsoft.com/kb/148652

     

    In additional , you can post us some codes or a sample, so that we can know about your issue more clearly and help you to resolve it.

     

     

    I hope my suggestion can help you to resolve your issue. if anything is unclear ,please feel free and let me know.

     

    Best Regards,

    Rob


    Rob Pan [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Rob Pan Friday, May 6, 2011 2:16 AM
    Tuesday, May 3, 2011 9:37 AM

All replies

  • #include <afxwin.h>

     will cause uafxcwd.lib to be linked in.

    Wednesday, April 27, 2011 4:03 AM
  • Hi,

     

    According to my knowledge, it seems that it is a link issue in your project. The CRT libraries use weak external linkage for the new, delete, and DllMain functions. The MFC libraries also contain new, delete, and DllMain functions. These functions require the MFC libraries to be linked before the CRT library is linked. There are two ways to resolve this problem. The first solution involves forcing the linker to link the libraries in the correct order. The second solution allows you to find the module that is causing the problem and to correct it.

     

    Here is the detail information about LNK 2005;

    1. http://support.microsoft.com/kb/148652

     

    In additional , you can post us some codes or a sample, so that we can know about your issue more clearly and help you to resolve it.

     

     

    I hope my suggestion can help you to resolve your issue. if anything is unclear ,please feel free and let me know.

     

    Best Regards,

    Rob


    Rob Pan [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Rob Pan Friday, May 6, 2011 2:16 AM
    Tuesday, May 3, 2011 9:37 AM