以下代码来自对问题398069的回答。它在Linux下以及在优化模式下的Windows下非常有效。不幸的是,我的应用程序在Windows下崩溃,我必须调试它......
template <class T>
T *set_the_global(T *candidate)
{
std::map<std::string,void*>::iterator r = MainFactoriesMap::mainFactoriesMap().find(std::string(typeid(*candidate).name()));
...
}
在调试模式下(Windows,使用qtcreator,cmake 2.8.2,Visual C ++ 10,Qt和boost可用作调试而不是调试),对typeid的调用,在进入main之前发生,崩溃,抛出异常看来。我强制使用/ GR选项。没有区别......
我在调试和输出模式下面调用了编译器和链接器。请注意,我尝试在Visual Studio下编译所有内容但它失败了(但这将是另一个问题)。
Optim build:它有效
c:\PROGRA~2\MICROS~2.0\VC\bin\amd64\cl.exe /Zc:wchar_t- /EHsc /GR /MD /O2 /Ob2 /D NDEBUG -IE:\Projets\Amose\Sources\lima_common\src -IC:\Qt\v4.8.2\include -IC:\Qt\v4.8.2\include\QtXml -IC:\Qt\v4.8.2\include\QtCore -IC:\PROGRA~1\boost\BOOST_~1\include -Ic:\amose\include -D DEBUG_CD -D WIN32 -D QT_NO_KEYWORDS -Dlima_common_factory_EXPORTS -DQT_DLL -DQT_XML_LIB -DQT_CORE_LIB -DBOOST_ALL_DYN_LINK -DLIMA_FACTORY_EXPORTING -DQT_NO_DEBUG /TP /FoCMakeFiles\lima-common-factory.dir\AmosePluginsManager.cpp.obj /FdC:\amose-vcbuild\lima-common\src\common\AbstractFactoryPattern\lima-common-factory.pdb -c E:\Projets\Amose\Sources\lima_common\src\common\AbstractFactoryPattern\AmosePluginsManager.cpp
...
“C:\ Program Files(x86)\ CMake 2.8 \ bin \ cmake.exe”-E vs_link_dll c:\ PROGRA~2 \ MICROS~2.0 \ VC \ bin \ amd64 \ link.exe @CMakeFiles \ lima-common-factory .dir \ objects1.rsp /out:lima-common-factory.dll /implib:lima-common-factory.lib / pdb:C:\ amose-vcbuild \ lima-common \ src \ common \ AbstractFactoryPattern \ lima-common- factory.pdb / dll /version:0.0 / STACK:10000000 / machine:x64 / INCREMENTAL:NO -LIBPATH:C:\ PROGRA~1 \ boost \ BOOST_~1 \ lib -LIBPATH:c:\ amose \ lib .. \ QsLog \ lima-common-qslog.lib .. \ misc \ lima-common-misc.lib .. \ Data \ lima-common-data.lib .. \ QsLog \ lima-common-qslog.lib C:\ Qt \ v4.8.2 \ lib \ QtXml4.lib C:\ Qt \ v4.8.2 \ lib \ QtCore4.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib
调试版本:失败
c:\PROGRA~2\MICROS~2.0\VC\bin\amd64\cl.exe /Zc:wchar_t- /EHsc /GR /D_DEBUG /MDd /Zi /Ob0 /Od /RTC1 -IE:\Projets\Amose\Sources\lima_common\src -IC:\Qt\v4.8.2\include -IC:\Qt\v4.8.2\include\QtXml -IC:\Qt\v4.8.2\include\QtCore -IC:\PROGRA~1\boost\BOOST_~1\include -Ic:\amose-debug\include -D DEBUG_CD -D WIN32 -D QT_NO_KEYWORDS -Dlima_common_factory_EXPORTS -DQT_DLL -DQT_XML_LIB -DQT_CORE_LIB -DBOOST_ALL_DYN_LINK -DLIMA_FACTORY_EXPORTING -DQT_DEBUG /TP /FoCMakeFiles\lima-common-factory.dir\AmosePluginsManager.cpp.obj /FdC:\amose-vcbuild\lima-common-debug\src\common\AbstractFactoryPattern\lima-common-factoryd.pdb -c E:\Projets\Amose\Sources\lima_common\src\common\AbstractFactoryPattern\AmosePluginsManager.cpp
...
“C:\ Program Files(x86)\ CMake 2.8 \ bin \ cmake.exe”-E vs_link_dll c:\ PROGRA~2 \ MICROS~2.0 \ VC \ bin \ amd64 \ link.exe @CMakeFiles \ lima-common-factory .dir \ objects1.rsp /out:lima-common-factoryd.dll /implib:lima-common-factoryd.lib / pdb:C:\ amose-vcbuild \ lima-common-debug \ src \ common \ AbstractFactoryPattern \ lima- common-factoryd.pdb / dll /version:0.0 / STACK:10000000 / machine:x64 / debug / INCREMENTAL -LIBPATH:C:\ PROGRA~1 \ boost \ BOOST_~1 \ lib -LIBPATH:c:\ amose-debug \ lib .. \ QsLog \ lima-common-qslogd.lib .. \ misc \ lima-common-miscd.lib .. \ Data \ lima-common-datad.lib .. \ QsLog \ lima-common-qslogd.lib C :\ Qt \ v4.8.2 \ lib \ QtXmld4.lib C:\ Qt \ v4.8.2 \ lib \ QtCored4.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid。 lib comdlg32.lib advapi32.lib
使用qtcreator显示debuging会话: