This questiod had been brought up numerous times, but Visual Studio never gives up to challange me.
We have an application that should be self sufficient, i.e not depend on any dlls. This is why we build everything statically with MT(d) code generation flags.
The app depends on Qt, zlib, OpenSSL and DCMTK. All of them were built as static libs with MT(d). The app alwo uses some MFC stuff, so we also have to link against it.
MFC is inluded with
#include <afxwin.h>
I read somewhere that this should be the first include in every file, but not sure if it is ture. Anyway, it is not included in every file, just one file inlucdes it.
Here are the link errors:
Error 24 error LNK2005: "void __cdecl operator delete[](void *)" (??_V@YAXPAX@Z) already defined in LIBCMTD.lib(delete2.obj) uafxcwd.lib
Error 22 error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in LIBCMTD.lib(dbgdel.obj) uafxcwd.lib
Error 23 error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) already defined in libcpmtd.lib(newaop.obj) uafxcwd.lib
Error 21 error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj) uafxcwd.lib
Here is the linker output: http://pastebin.com/9qWbnbC5
I read may threads on many sites as well as the MSDN KB article http://support.microsoft.com/kb/148652, But can't help myself. All of them keep saying that MFC libs should be linked before CRT, but I can not find a way to alter the linking order.
An help is greatly appreciated.
Edit 1: Using the trick from this thread actually resolves the problem, but I still want to know what's wrong here. http://stackoverflow.com/questions/1146338/error-lnk2005-new-and-delete-already-defined-in-libcmtd-libnew-obj Edit 2: Visual Studio 2008 SP1 Windows 7 Qt 4.6.3