다음을 통해 공유


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
.

Comments

  • Anonymous
    September 29, 2006
    The comment has been removed

  • Anonymous
    October 04, 2006
    I doubt that pre-compiled headers support may have anything to do with this error. I would look for different compilation switches on files in project. Perhaps the same dev have set some compiler options of each file.

  • Anonymous
    January 07, 2008
    The comment has been removed

  • Anonymous
    April 17, 2008
    You are probably aware that this problem also arises when trying to link .C files compiled as 'C' with an MFC app.  I had a similar problem trying to link nafxcwd.lib and Libcmtd.lib.  I previously fixed this for a VC6 project.  (Basically, you are forcing the order in which the libraries are used by removing them from the list the linker thinks it needs and then manually add them back in.) Having ported the project to VS2003, I knew what needed to be fixed but couldn't remember the steps. Thanks for the instructions - it saves me having to experiment.

  • Anonymous
    January 16, 2009
    <a href= http://svipuoo.angelfire.com >cca catalog shopping</a> <a href= http://bkoszlj.angelfire.com >centruy 21 professional realty in hudson florida</a> <a href= http://etcighj.angelfire.com >automax dealership killeen</a> <a href= http://xdviqoc.angelfire.com >blue bells drawings and sketches</a> <a href= http://jdmmsok.angelfire.com >bridgewaters seaport</a>

  • Anonymous
    June 16, 2009
    PingBack from http://workfromhomecareer.info/story.php?id=16846

  • Anonymous
    June 16, 2009
    PingBack from http://lowcostcarinsurances.info/story.php?id=4908