GDI+ 应用,Release没有错误,Debug很多。
问题描述:
在VC6环境中,一个界面工程利用了GDI+的一些库,Release模式下编译、运行无误,但在Debug模式下就会报告错误。
xxx.cpp D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\crtdbg.h(536) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\crtdbg.h(536) : error C2059: syntax error : 'newline' D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(674) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(674) : error C2059: syntax error : 'newline' D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(674) : error C2238: unexpected token(s) preceding ';' D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(675) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(675) : error C2059: syntax error : 'newline' D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(675) : error C2238: unexpected token(s) preceding ';' D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(683) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(683) : error C2059: syntax error : 'newline' D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(683) : error C2238: unexpected token(s) preceding ';' D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(1631) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(1631) : error C2059: syntax error : 'newline' D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(122) : error C2059: syntax error : 'string' D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(123) : error C2091: function returns function D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(123) : error C2802: static member 'operator new' has no formal parameters D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(123) : error C2333: 'new' : error in function declaration; skipping function body D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(131) : error C2059: syntax error : 'string' D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(131) : error C2091: function returns function D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(131) : error C2802: static member 'operator new' has no formal parameters D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(135) : error C2059: syntax error : 'string' D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(135) : error C2091: function returns function D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(135) : error C2556: 'void *(__cdecl *__stdcall CNoTrackObject::operator new(void))(unsigned int,const char *,int)' : overloaded function differs only by return type from 'void *(__c decl *__stdcall CNoTrackObject::operator new(void))(unsigned int)' D:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(131) : see declaration of 'new' D:\123 debug\UI\../ui/gdi/Includes/GdiplusBase.h(25) : error C2059: syntax error : 'string' D:\123 debug\UI\../ui/gdi/Includes/GdiplusBase.h(26) : error C2091: function returns function D:\123 debug\UI\../ui/gdi/Includes/GdiplusBase.h(26) : error C2802: static member 'operator new' has no formal parameters D:\123 debug\UI\../ui/gdi/Includes/GdiplusBase.h(26) : error C2333: 'new' : error in function declaration; skipping function body D:\123 debug\UI\../ui/gdi/Includes/GdiplusBase.h(33) : error C2059: syntax error : 'string' D:\123 debug\UI\../ui/gdi/Includes/GdiplusBase.h(33) : error C2090: function returns array D:\123 debug\UI\../ui/gdi/Includes/GdiplusBase.h(35) : error C2059: syntax error : 'return' D:\123 debug\UI\../ui/gdi/Includes/GdiplusBase.h(35) : error C2238: unexpected token(s) preceding ';' D:\123 debug\UI\../ui/gdi/Includes/GdiplusBase.h(37) : error C2143: syntax error : missing ';' before '}' D:\123 debug\UI\../ui/gdi/Includes/GdiplusHeaders.h(26) : error C2504: 'GdiplusBase' : base class undefined D:\123 debug\UI\../ui/gdi/Includes/GdiplusHeaders.h(195) : error C2504: 'GdiplusBase' : base class undefined D:\123 debug\UI\../ui/gdi/Includes/GdiplusHeaders.h(275) : error C2504: 'GdiplusBase' : base class undefined D:\123 debug\UI\../ui/gdi/Includes/GdiplusHeaders.h(349) : error C2504: 'GdiplusBase' : base class undefined D:\123 debug\UI\../ui/gdi/Includes/GdiplusHeaders.h(436) : error C2504: 'GdiplusBase' : base class undefined D:\123 debug\UI\../ui/gdi/Includes/GdiplusHeaders.h(684) : error C2504: 'GdiplusBase' : base class undefined D:\123 debug\UI\../ui/gdi/Includes/GdiplusHeaders.h(770) : error C2504: 'GdiplusBase' : base class undefined D:\123 debug\UI\../ui/gdi/Includes/GdiplusImageAttributes.h(39) : error C2504: 'GdiplusBase' : base class undefined D:\123 debug\UI\../ui/gdi/Includes/GdiplusMatrix.h(16) : error C2504: 'GdiplusBase' : base class undefined D:\123 debug\UI\../ui/gdi/Includes/GdiplusBrush.h(25) : error C2504: 'GdiplusBase' : base class undefined D:\123 debug\UI\../ui/gdi/Includes/GdiplusPen.h(22) : error C2504: 'GdiplusBase' : base class undefined D:\123 debug\UI\../ui/gdi/Includes/GdiplusStringFormat.h(20) : error C2504: 'GdiplusBase' : base class undefined D:\123 debug\UI\../ui/gdi/Includes/GdiplusPath.h(19) : error C2504: 'GdiplusBase' : base class undefined D:\123 debug\UI\../ui/gdi/Includes/GdiplusPath.h(1035) : error C2504: 'GdiplusBase' : base class undefined D:\123 debug\UI\../ui/gdi/Includes/GdiplusLineCaps.h(146) : error C2661: 'new' : no overloaded function takes 3 parameters D:\123 debug\UI\../ui/gdi/Includes/GdiplusGraphics.h(22) : error C2504: 'GdiplusBase' : base class undefined D:\123 debug\UI\../ui/gdi/Includes/GdiplusRegion.h(89) : error C2661: 'new' : no overloaded function takes 3 parameters D:\123 debug\UI\../ui/gdi/Includes/GdiplusRegion.h(118) : error C2661: 'new' : no overloaded function takes 3 parameters D:\123 debug\UI\../ui/gdi/Includes/GdiplusFontCollection.h(54) : error C2661: 'new' : no overloaded function takes 3 parameters D:\123 debug\UI\../ui/gdi/Includes/GdiplusFontFamily.h(141) : error C2661: 'new' : no overloaded function takes 3 parameters D:\123 debug\UI\../ui/gdi/Includes/GdiplusFont.h(186) : error C2661: 'new' : no overloaded function takes 3 parameters D:\123 debug\UI\../ui/gdi/Includes/GdiplusBitmap.h(119) : error C2661: 'new' : no overloaded function takes 3 parameters D:\123 debug\UI\../ui/gdi/Includes/GdiplusBitmap.h(131) : error C2661: 'new' : no overloaded function takes 3 parameters D:\123 debug\UI\../ui/gdi/Includes/GdiplusBitmap.h(149) : error C2661: 'new' : no overloaded function takes 3 parameters D:\123 debug\UI\../ui/gdi/Includes/GdiplusBitmap.h(386) : error C2661: 'new' : no overloaded function takes 3 parameters D:\123 debug\UI\../ui/gdi/Includes/GdiplusBitmap.h(761) : error C2661: 'new' : no overloaded function takes 3 parameters D:\123 debug\UI\../ui/gdi/Includes/GdiplusBitmap.h(773) : error C2661: 'new' : no overloaded function takes 3 parameters D:\123 debug\UI\../ui/gdi/Includes/GdiplusBitmap.h(781) : error C2661: 'new' : no overloaded function takes 3 parameters D:\123 debug\UI\../ui/gdi/Includes/GdiplusBitmap.h(789) : error C2661: 'new' : no overloaded function takes 3 parameters D:\123 debug\UI\../ui/gdi/Includes/GdiplusBitmap.h(798) : error C2661: 'new' : no overloaded function takes 3 parameters D:\123 debug\UI\../ui/gdi/Includes/GdiplusBitmap.h(806) : error C2661: 'new' : no overloaded function takes 3 parameters D:\123 debug\UI\../ui/gdi/Includes/GdiplusBitmap.h(814) : error C2661: 'new' : no overloaded function takes 3 parameters D:\123 debug\UI\../ui/gdi/Includes/GdiplusBitmap.h(871) : error C2661: 'new' : no overloaded function takes 3 parameters D:\123 debug\UI\../ui/gdi/Includes/GdiplusBitmap.h(916) : error C2661: 'new' : no overloaded function takes 3 parameters D:\123 debug\UI\../ui/gdi/Includes/GdiPlus.h(152) : error C2143: syntax error : missing ';' before '}' D:\123 debug\UI\../ui/gdi/Includes/GdiPlus.h(152) : error C2143: syntax error : missing ';' before '}' D:\123 debug\UI\../ui/gdi/Includes/GdiPlus.h(152) : error C2143: syntax error : missing ';' before '}' D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\new(35) : error C2059: syntax error : 'string' D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\new(35) : error C2091: function returns function D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\new(35) : error C2809: 'operator new' has no formal parameters D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\new(36) : error C2059: syntax error : 'string' D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\new(37) : error C2091: function returns function D:\Program Files\Microsoft Visual Studio\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 op erator new(void))(unsigned int)' D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\new(35) : see declaration of 'new' D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\memory(16) : error C2059: syntax error : 'string' D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\memory(17) : error C2091: function returns function D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\memory(17) : error C2784: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,class std::allocator<`template-parameter257'> &)' : could not deduce template argument for 'void *(__cdecl *)(u nsigned int,class std::allocator<_Ty> &)' from 'void *(__cdecl *)(unsigned int)' D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\memory(17) : error C2785: 'void *(__cdecl *__cdecl operator new(void))(unsigned int,class std::allocator<`template-parameter257'> &)' and 'void *(__cdecl *__cdecl operator new(void))(unsigned int )' have different return types D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\memory(16) : see declaration of 'new' D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\memory(17) : error C2809: 'operator new' has no formal parameters D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\memory(20) : error C2954: template definitions cannot nest D:\123 debug\UI\SkinManager.cpp(39) : error C2661: 'new' : no overloaded function takes 3 parameters 执行 cl.exe 时出错. Creating browse info file... 123.exe - 1 error(s), 0 warning(s)
出错原因:
错误提示的那个CPP文件中,将这部分 宏定义的头部去掉。 #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif /* 因为此时DEBUG版本中的new 已经被另外一个宏定义过了。Debug下系统调用new的时候果然不是听从基类GdiplusBase中new的, 而是Afx.h中那里的new(这时的确有三个参数),按理系统编译到这里应该提示出错在这行:*/
#ifndef _GDIPLUSBASE_H #define _GDIPLUSBASE_H class GdiplusBase { public: void (operator delete)(void* in_pVoid) { DllExports::GdipFree(in_pVoid); } void* (operator new)(size_t in_size) { return DllExports::GdipAlloc(in_size); } void (operator delete[])(void* in_pVoid) { DllExports::GdipFree(in_pVoid); } void* (operator new[])(size_t in_size) { return DllExports::GdipAlloc(in_size); } }; #endif
跟踪错误:
1、到达AFX.H的
void* PASCAL operator new(size_t nSize); void* PASCAL operator new(size_t, void* p); void* AFX_CDECL operator new(size_t nSize, LPCSTR lpszFileName, int nLine); // non-_DEBUG_ALLOC version that assume everything is OK #define DEBUG_NEW new
再加上系统自动生成的下面两行:
#ifdef _DEBUG
#define new DEBUG_NEW
即Debug下系统调用new的时候果然不是听从基类GdiplusBase中new的,而是Afx.h中那里的new(这时的确有三个参数),按理系统编译到这里应该提示出错在这行:
void* AFX_CDECL operator new(size_t nSize, LPCSTR lpszFileName, int nLine);
但它下面这行代码:#define DEBUG_NEW new(THIS_FILE, __LINE__)使得出错行提示又在我的代码中调用new的这行:
m_instance = new UIManger(); //采用单例模式
系统将三个参数的默认new 关键字的参数个数。
结果:将上述删除后,Debug就可通过。
附述:
发现很多下载的用Gdi+的例子在Debug下都有下面这样的错误:
gdiplus.lib(imagingguds.obj) : fatal error LNK1103: debugging information corrupt; recompile module
出现环境 xp sp2 + 最新 sdk + vc6 +vc7
出现此错误 位 vc6 下编译,问题出来 lib 和 link.exe 版本不合;
查看 lib 设置,将 sdk 移动到最后, 编译通过。
看来 xp 的 sdk 已经默认的向 vc.net 靠拢了
链接:http://bbs.csdn.net/topics/80358847