我将项目从VS2012升级到VS2013,发布版本正常运行,但调试版本在断言上失败。
在main
之前,我慢慢看RegisterCategory
超过最大类别数。单步执行调试器,它们看起来都是合理的标题类别,然后事情就失败了。
令人困惑的是,atltrace.h
中的功能(如下所示)似乎不止一次被调用。对于不同的功能地址,我认为如果不是32限制,这不会是一个问题。
__declspec(selectany) CTraceCategoryEx<CTraceCategoryEx<>::TraceISAPI> atlTraceISAPI(_T("atlTraceISAPI"));
怎么回事?我可以禁用atltrace吗?
static void RegisterCategory(_In_z_ LPCTSTR pszCategory, unsigned int nCategory)
{
if (pszCategory == nullptr)
{
return;
}
if (m_nLastCategory >= MaxCategoryArray)
{
ATLASSERT(false && "Too many categories defined");
return;
}
m_nMap[m_nLastCategory].nCategory = nCategory;
#ifdef _UNICODE
wcscpy_s(m_nMap[m_nLastCategory].categryName, MaxLengthOfCategoryName - 1, pszCategory);
#else
wchar_t buffer[MaxLengthOfCategoryName] = { 0 };
swprintf_s(buffer, MaxLengthOfCategoryName - 1, L"%S", pszCategory);
wcscpy_s(m_nMap[m_nLastCategory].categryName, MaxLengthOfCategoryName - 1, buffer);
#endif
m_nLastCategory++;
}
Linker 2012(工作)
/OUT:"C:\Users\kandel\Desktop\obfuscated\x64\Debug\\mine.exe" /MANIFEST /NXCOMPAT /PDB:"C:\Users\kandel\Desktop\obfuscated\x64\Debug\mine.pdb" /DYNAMICBASE "C:\Users\kandel\Desktop\fslim\\glew\glew-1.9.0\lib\glew32.lib" "C:\Users\kandel\Desktop\fslim\\glew\glew-1.9.0\lib\glew32mx.lib" "C:\Users\kandel\Desktop\fslim\\Andor SDK3\atcorem.lib" "BNSPCIeBoard.lib" "cudart.lib" "cuda.lib" "WINMM.lib" "libgmp-10.lib" "libtiff.lib" "qtmaind.lib" "Qt5Cored.lib" "Qt5Guid.lib" "Qt5OpenGLd.lib" "Qt5PrintSupportd.lib" "opengl32.lib" "glu32.lib" "Qt5Widgetsd.lib" "opencv_core300d.lib" "opencv_cuda300d.lib" "opencv_cudaarithm300d.lib" "opencv_cudaimgproc300d.lib" /DEBUG /MACHINE:X64 /PGD:"C:\Users\kandel\Desktop\obfuscated\x64\Debug\mine.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"x64\Debug\SLIM4.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"C:\Qt\5.2.1\msvc2012_64_opengl\lib" /LIBPATH:"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\lib\x64" /TLBID:1
VS 2013不工作
/OUT:"C:\Users\QLI\Desktop\obfuscated\x64\Debug\\mine.exe" /MANIFEST:NO /NXCOMPAT /PDB:"C:\Users\QLI\Desktop\obfuscated\x64\Debug\mine.pdb" /DYNAMICBASE "C:\Users\QLI\Desktop\obfuscated\\Andor SDK3\atcorem.lib" "BNSPCIeBoard.lib" "cudart.lib" "cuda.lib" "WINMM.lib" "libgmp-10.lib" "libtiff.lib" "qtmaind.lib" "Qt5Cored.lib" "Qt5Guid.lib" "Qt5OpenGLd.lib" "Qt5PrintSupportd.lib" "opengl32.lib" "glu32.lib" "Qt5Widgetsd.lib" "opencv_core300d.lib" "opencv_cuda300d.lib" "opencv_cudaarithm300d.lib" "opencv_cudaimgproc300d.lib" /DEBUG /MACHINE:X64 /PGD:"C:\Users\QLI\Desktop\obfuscated\x64\Debug\mine.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"x64\Debug\mine.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"C:\Qt\Qt5.3.1\5.3\msvc2013_64_opengl\lib" /LIBPATH:"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\lib\x64" /TLBID:1
这两者之间的主要区别在于,在VS2012中我可以选择no atl
并且一切运行正常/正确,其中在VS2013中我无法选择此选项。
- 编辑 -
我删除了除Qt和CUDA之外的所有外部库。注意到从预编译的标头中删除#include <afxwin.h>
会导致问题消失,但我需要使用afxwin.h
...
答案 0 :(得分:0)
我能够通过将代码的afx
部分移动到dll并删除标题来解决问题。为什么在VS版本之间更改此功能是一个挥之不去的问题。我只能通过更改可以注册的最大数字来断定MS破坏了我的代码。