Another doze of kitten cuteness, from May 2008. Enjoy!
Archive for June, 2008

“nafxcw.lib” error LNK2005 and “identifier ‘THIS_FILE’” error C2061
June 1, 2008I guess you also here and there stumble upon these errors while programming with MFC. Yet the approprite MSDN-KB articles are not very explicite about what to do.
So, here’s what typically works for me.
“nafxcw.lib” error LNK2005
If you get lots of LNK2005 errors like this:
nafxcwd.lib(afxmem.obj) : error LNK2005:
"void * __cdecl operator new(unsigned int)"(??2@YAPAXI@Z)
already defined in LIBCMTD.lib(new.obj)
nafxcwd.lib(afxmem.obj) : error LNK2005:
"void __cdecl operator delete(void *)"(??3@YAXPAX@Z)
already defined in LIBCMTD.lib(dbgnew.obj)
nafxcwd.lib(afxmem.obj) : error LNK2005:
"void * __cdecl operator new(unsigned int,int,char const *,int)"
(??2@YAPAXIHPBDH@Z) already defined in LIBCMTD.lib(dbgnew.obj)
mfcs40d.lib(dllmodul.obj): error LNK2005:
_DllMain@12 already defined in MSVCRTD.LIB (dllmain.obj)
mfcs42d.lib(dllmodul.obj): error LNK2005:
_DllMain@12 already defined in msvcrtd.lib (dllmain.obj)
make sure all your source (.cpp) files contain the #include "stdafx.h" as the first include in the file.
This error also appears when there is conflict in the way how CRT and MFC library are linked (static / shared), so if these errors appear after you have changed the way any of those is linked, check if you did it for both.
“identifier ‘THIS_FILE’” error C2061
If you got C2061 errors like
c:\program files\msvs6\vc98\include\new(35) :
error C2061: syntax error : identifier 'THIS_FILE'
c:\program files\msvs6\vc98\include\new(35) :
error C2091: function returns function
c:\program files\msvs6\vc98\include\new(35) :
error C2809: 'operator new' has no formal parameters
c:\program files\msvs6\vc98\include\new(36) :
error C2061: syntax error : identifier 'THIS_FILE'
c:\program files\msvs6\vc98\include\new(37) :
error C2091: function returns function
c:\program files\msvs6\vc98\include\new(37) :
error C2556: 'void *(__cdecl *__cdecl operator
new(void))(unsigned int,const struct std::nothrow_t &)' :
overloaded function differs only by return type from
'void *(__cdecl *__cdecl operator new(void))(unsigned int)'
c:\program files\msvs6\vc98\include\new(35) :
see declaration of 'new'
c:\program files\msvs6\vc98\include\new(42) :
error C2809: 'operator new' has no formal parameters
c:\program files\msvs6\vc98\include\new(42) :
error C2065: '_P' : undeclared identifier
make sure all your #include’s occure ahead of the
#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif
section in the source files; esp. the headers you created, and that are not generated/created by VS.

