如何针对发布版本的lib(MSVCRT.lib)构建调试.exe(MSVCRTD.lib)?

App*_*ood 5 c++ linker visual-studio visual-c++

我正在使用Visual C++ 2008,SP1.我在调试构建配置中有一个QT应用程序(gui,.exe).它设置为使用CRT的多线程调试DLL版本,即MSVCRTD.lib.

我正在链接第三方库,该库是在发布模式下构建的,并使用CRT的多线程DLL(非调试)版本,即MSVCRT.lib.

它链接并运行但在启动时崩溃.在链接时我收到警告:

链接:警告LNK4098:defaultlib'MSVCRT'与使用其他库冲突; 使用/ NODEFAULTLIB:库

我尝试设置/NODEFAULTLIB:msvcrt.lib

但由于缺少符号,导致5个链接错误.

所以不可能使用两个不同的库吗?有什么选择?我可以从我拥有的第三方库中创建一个DLL吗?或者这是第三方必须做的事情?

启动时的例外是:

"在MyApp.exe中......处理未处理的异常:......访问冲突读取位置0x00000000f"

以下是应用程序运行后的调用堆栈,它崩溃了:

MyApp.exe!std::_Aux_cont::_Getcont()  + 0xa bytes   C++
MyApp.exe!std::_Iterator_base_aux::_Getmycont()  + 0x1b bytes   C++
MyApp.exe!std::_Tree<std::_Tmap_traits<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,unsigned int,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,unsigned int> >,0> >::const_iterator::operator*()  + 0x28 bytes  C++
MyApp.exe!std::_Tree<std::_Tmap_traits<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,unsigned int,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,unsigned int> >,0> >::iterator::operator*()  + 0xf bytes C++
MyApp.exe!std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,unsigned int,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,unsigned int> > >::operator[]()  + 0xe9 bytes    C++
MyApp.exe!ThirdPartyLib::client::`anonymous namespace'::init_xlt_mode()  + 0x5f bytes   C++
MyApp.exe!_GetCommandLineW@0()  + 0x8d8f3 bytes C++
msvcr90d.dll!_initterm(void (void)* * pfbegin=0x006c4468, void (void)* * pfend=0x006cb0b8)  Line 903    C
MyApp.exe!__tmainCRTStartup()  Line 501 + 0xf bytes C
MyApp.exe!WinMainCRTStartup()  Line 403 C
kernel32.dll!7c817067()     
Run Code Online (Sandbox Code Playgroud)

Aar*_*ela 10

您可以构建项目以链接发布CRT并为代码启用调试信息.在"项目属性"中,转到C++/General并更改调试信息格式.在"优化"部分中,关闭优化.切换到"链接器/调试"部分并启用调试信息的生成.确保设置程序数据库文件(PDB).

此时,您的应用程序将为您的代码中的所有内容发出调试信息,并链接到非调试DLL CRT.这使您可以在Release配置中调试应用程序,同时避免在同一应用程序中使用多个CRT相关的问题.