Most MFC programs use MFC in a shared DLL, but each version of VS requires an MFC runtime, which is a bit annoying.
So I chose to use the static MFC library, although the file will be larger, but at least no trouble.
Vs this is not good enough, by default it actually error:
VC Compile Error:1>uafxcw.lib (afxmem.obj): Error LNK2005:"void * __cdecl operator new (unsigned int)"(??2@[email protected]) is already in LIBCMT.lib (New. obj) defined in1>uafxcw.lib (afxmem.obj): Error LNK2005:"void __cdecl operator delete (void *)"(??3@[email protected]) is already in LIBCMT.lib (Delete. obj) defined in1>uafxcw.lib (afxmem.obj): Error LNK2005:"void * __cdecl operator new[] (unsigned int)"(??[email protected]@z] already defined in LIBCMT.lib (new2.obj)1A. /bin/tllogger_unicode_release.exe:fatal Error LNK1169: Find one or more multi-definition symbols
Online search, found that there is no obvious problem, that is, MFC is Unicode or muiltibytes. In short, vs hides a lot of detail, but we need to understand these details in order to solve the problem!
Here I do a full complement:
First determine two libraries: the previous one is the static Library of MFC, the latter is the static library of C
Unicode Debug===========uafxcwd.lib;libcmtd.lib; Unicode Release===========uafxcw.lib;libcmt.lib; Multibytes Debug===========nafxcwd.lib;libcmtd.lib; Multibytes Release===========nafxcw.lib;libcmt.lib;
The solution is then:
(in three steps) first, configure the use of MFC for use in the static Library using MFC: Properties , General, MFC,Select " use MFC in Static Library", and then, configure the Runtime: property ->c /c++-> code Generation--run library, select " Multithreading (/MT)" Three, finally, Add Nafxcw.lib and LIBCMT.lib two library files to additional dependencies: (Note: The library nafxcw.lib must precede the library LIBCMT.lib, which is the MFC static link library, which is the C run-time library) properties, linker Additional dependencies, add Nafxcw.lib and LIBCMT.lib
Workaround: http: // blog.vckbase.com/zaboli/archive/2010/02/05/40921.aspx New,deletenew,delete , and DllMain functions. These functions require that you link the MFC library before you link the CRT library. The following LNK2005 errors may occur when the link order of the C run-time (CRT) library and the Microsoft Foundation Class (MFC) library is incorrect. WORKAROUND: Force the linker to link the library in the correct order! Project->properties->linker->ignore specific Library add uafxcwd.lib Libcmtd.lib (Input- Ignore specific libraries) add Uafxcwd.lib Libcmtd.lib (Input -additional option) in additional dependencied
Reference Links:
http://blog.csdn.net/lejun2011/article/details/8115463
http://blog.csdn.net/liucanrui/article/details/6453986
---restore content ends---
How MFC uses the static MFC library