混合调试和发布库/二进制 - 坏实践? [英] Mixing debug and release library/binary - bad practice?

查看:117
本文介绍了混合调试和发布库/二进制 - 坏实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在调试二进制文件中使用第三方库的发行版本是不好的做法吗?

Is it a bad practice to use a release version of 3rd party library in debug binary?

我使用第三方库并编译了.lib库。我的exe是在调试模式开发。然后我得到:

I am using a 3rd party library and compiled a release .lib library. My exe is in debug mode development. Then I got:

error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in test1.obj

在一些googling之后,我发现这是因为我试图混合release与debug,我可能应该在调试模式下编译库,否则会混淆_ITERATOR_DEBUG_LEVEL宏。但我只是好奇,如果这是推荐的方式,为什么。看起来很麻烦,我需要编译和保持发布和调试二进制文件的记录为我打算使用的每个第三方库,这将是很多很快,而无意调试这些代码。

After some googling I found that is because I am trying to mix release with debug, and I should probably compile the library in debug mode or otherwise muddle with the _ITERATOR_DEBUG_LEVEL macro. But I am just curious if that is the recommanded way and why. It just seem cumbersome that I need to compile and keep a record of both release and debug binaries for every 3rd party library I intend to use, which will be many very soon, while having no intention to debug into these code.

推荐答案

混合调试和发布代码是不好的做法。问题是,不同的版本可以依赖于C ++运行时库的不同基本部分,例如如何分配内存,诸如迭代器之类的结构可能不同,可以生成额外的代码来执行操作(例如检查的迭代器)。

Mixing debug and release code is bad practice. The problem is that the different versions can depend on different fundamental parts of the C++ runtime library, such as how memory is allocated, structures for things like iterators might be different, extra code could be generated to perform operations (e.g. checked iterators).

它与使用其他不同设置构建的库文件相同。想象一下,头文件包含应用程序和库使用的结构的情况。库是用结构打包和对齐设置为一个值和应用程序构建与另一个。不能保证将结构从应用程序传递到库中,因为它们的大小和成员位置可能不同。

It's the same as mixing library files built with any other different settings. Imagine a case where a header file contains a structure that is used by both application and library. The library is built with structure packing and alignment set to one value and the application built with another. There are no guarantees that passing the structure from the application into the library will work since they could vary in size and member positions.

是否可以构建您的第三方库作为DLL?假设任何函数的接口是干净的,并且不尝试传递任何STL对象,您将能够混合调试应用程序与释放DLL,没有问题。

Is it possible to build your 3rd party libraries as DLLs? Assuming the interface to any functions is cleaner and does not try to pass any STL objects you will be able to mix a debug application with release DLLs without problems.

这篇关于混合调试和发布库/二进制 - 坏实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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