How to Fix "Multiply Defined Functions" when Mixing C/C++ and MFC Static Libraries
SummaryAt times, you want to have your MFC application in a single EXE file. Then you need to link MFC libraries statically. Visual Studio will give link errors in this case if you are also linking some C/C++ libraries. This post details the work around to fix the problem.
The ProblemIf your project contains static C/C++ libraries and MFC code and MFC is statically linked, you will most likely get link errors:
error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMT.lib
MSDN Solution
MSDN article http://support.microsoft.com/kb/148652 shows how to work around the problem.
Basically, you need to change the order of some default link-in libraries. In project link settings
- You first ignore default libraries: Nafxcw.lib;Libcmt.libi>
- You then add additional dependencies: Nafxcw.lib;Libcmt.lib
MSDN article is missing some details. Below are the library names to use if your are using Debug configuration or using Unicode:
For Debug config., the library files are : Nafxcwd.lib;Libcmtd.lib If you are using Unicode, then change Nafxcwd.lib to Uafxcwd.libAnother Acompanying Problem
You may also get this error for Release configurations:
MSB6006: "mt.exe" exited with code 31.
To fix this error, you can either do a [Rebuild All] or set link option[Manifest File] -> [Generate Manifest] to No
*** END ***