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

How do you build a debug .exe (MSVCRTD.lib) against a release built lib (MSVCRT.lib)?(如何针对发布构建的库 (MSVCRT.lib) 构建调试 .exe (MSVCRTD.lib)?)

本文介绍了如何针对发布构建的库 (MSVCRT.lib) 构建调试 .exe (MSVCRTD.lib)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using Visual C++ 2008, SP1. I have a QT app (gui, .exe) in debug build config. It's set to use the Multi-threaded Debug DLL version of the CRT, aka MSVCRTD.lib.

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

I'm linking against a 3rd party library that is built in release mode and using the Multi-threaded DLL (non-debug) version of the CRT, aka MSVCRT.lib.

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

It links and runs but crashes at startup. While linking I get the warning:

LINK:警告 LNK4098:defaultlib 'MSVCRT' 与其他库的使用冲突;使用/NODEFAULTLIB:library

LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library

我尝试设置/NODEFAULTLIB:msvcrt.lib

I tried setting /NODEFAULTLIB:msvcrt.lib

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

but that resulted in 5 linking errors due to missing symbols.

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

So is it not possible to use two different libs? What is the alternative? Can I create a DLL out of the 3rd party lib I have? Or is that something the 3rd party would have to do?

启动时的异常是:

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

"Unhandled exception at ....... in MyApp.exe: ...... Access violation reading location 0x00000000f"

以下是应用运行后崩溃后的调用栈:

The following is the call stack after the app is run and it crashes:

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()     

推荐答案

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

You could build your project to link against the release CRT and enable debug information for your code. In "Project Properties" go to C++/General and change the Debug Information Format. In the "Optimization" section turn off optimization. Switch to the "Linker/Debugging" section and enable generation of debug info. Make sure to set the program database file (PDB).

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

At this point your application will emit debugging information for everything in your code and link against the non-debug DLL CRT. This enables you to debug your application in a Release configuration while avoiding the problems associated with using multiple CRTs in the same application.

这篇关于如何针对发布构建的库 (MSVCRT.lib) 构建调试 .exe (MSVCRTD.lib)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何针对发布构建的库 (MSVCRT.lib) 构建调试 .exe (MSVCRTD.lib)?

基础教程推荐