以下代码来自对问题 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 可作为调试而不是调试),在进入 main 之前发生的对 typeid 的调用崩溃,似乎抛出异常。我强制使用 /GR 选项。没什么区别...
我将在调试和输出模式下对编译器和链接器的调用放在下面。请注意,我尝试在 Visual Studio 下编译所有内容,但失败了(但这将是另一个问题)。
Optim 构建:它有效
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 显示调试会话: