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

查看:222
本文介绍了如何针对已发布的库(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.

我链接到第三方库,它是在发布模式并使用多线程DLL(非调试)版本的CRT,也就是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:warning LNK4098:defaultlib'MSVCRT'与使用其他库冲突; use / 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

由于缺少符号而导致的错误。

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

那么是不是可以使用两个不同的库?什么是替代方法?我可以从第三方库中创建一个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 ++ /常规并更改调试信息格式。在优化部分,关闭优化。切换到链接器/调试部分并启用生成调试信息。请确保设置程序数据库文件(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)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆