Linking to MFC and CRT dynamically and statically in one image

If you link your MFC application that consumes MFC static lib, often you may encounter a situation when your app dynamically links to MFC and your library statically links to MFC. When you build this application and you are going to get similar to ones listed below:

1>msvcrtd.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in libcmtd.lib(typinfo.obj)

1>msvcrtd.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in libcmtd.lib(typinfo.obj)

1>LINK : warning LNK4098: defaultlib 'mfc80ud.lib' conflicts with use of other libs; use /NODEFAULTLIB:library

1>LINK : warning LNK4098: defaultlib 'mfcs80ud.lib' conflicts with use of other libs; use /NODEFAULTLIB:library

1>LINK : warning LNK4098: defaultlib 'msvcrtd.lib' conflicts with use of other libs; use /NODEFAULTLIB:library

To resolve these errors, you need to link to MFC in one way across your solution. It can be either statically or dynamically and you need to decide which one you need. Then check Project Properties for all projects in your solution. Look for /D_AFXDLL. Look for how /MD[d] vs. /MT[d]. All your projects have to have one setting here - either all of them define _AFXDLL and do /MDd, or none defines _AFXDLL and all of them statically linked to MFC.

Note that I do not actively post on MFC framework anymore because it was not the main area of my focus. Last years I was posting on web
services
, program
and project
management
. Below are some other posts on MFC:

  1. Windows Forms and MFC Integration using CWinFormDialog
  2. Complete
    Example of MFC and Windows Forms Integration
  3. Integrating
    Windows Vista Aero Wizards into existing MFC Applications
    .
  4. Resolving
    common error around resolving private member during porting MFC
    applications
    .

If you have questions and need more help in integrating Windows Forms in your
MFC applications, please ask questions on Visual C++
MFC forum
.