混合调试和发布库/二进制文件 - 不好的做法? [英] Mixing debug and release library/binary - bad practice?

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

问题描述

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

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

我正在使用第 3 方库并编译了一个发行版 .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

经过一些谷歌搜索后,我发现这是因为我试图将发布与调试混合在一起,我可能应该在调试模式下编译库,或者以其他方式混淆 _ITERATOR_DEBUG_LEVEL 宏.但我只是好奇这是否是推荐的方式以及为什么.我需要为我打算使用的每个 3rd 方库编译并保留发布和调试二进制文件的记录,这似乎很麻烦,这很快就会很多,而无意调试这些代码.

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.

是否可以将您的第 3 方库构建为 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天全站免登陆