为什么不能互换使用库的调试/发布版本
在 C++ 中,大多数库都有调试/发布版本。 问题 1. 调试版本和发布版本之间的最大区别是什么(例如,使用其中一种版本与另一种版本相比有什么优势)。
问题 2. lib 只是函数的实现,如果您使用调试/发布版本,函数实现会如何变化?
问题 3. 您可以在调试模式下构建应用程序并使用库的发布版本吗?
谢谢。
In C++, most of the libs come in Debug/Release versions.
Question 1. What are the big difference between Debug and Release versions (e.g. what advantages do you have using one versus the other).
Question 2. A lib is just has an implementation of the functions, how does a function implementation change if you are using debug/release versions?
Question 3. Can you ever build your app in debug mode and use a release version of a lib?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
回答 1
调试模式
#ifdef DEBUG
块中的代码发布模式
答案 2
答案 3
Answer 1
Debug Mode
#ifdef DEBUG
blockRelease Mode
Answer 2
Answer 3
调试版本通常是在很少的优化的情况下构建的——因此,当您在带有源代码的调试器中单步调试它们时,很有可能在源代码行和程序中发生的事情之间存在良好的映射。当您单步调试高度优化的代码时,它不能很好地映射回源代码,并且更难以调试。
此外,每当有人使用
#ifdef DEBUG
或等效代码时,该代码在发行版本中不存在(当然)。这可能是额外的错误检查、日志记录、断言等。通常,调试和发布之间的函数接口不应该有所不同,因此您通常可以将调试和发布链接在一起而不会遇到太多麻烦。
然而,在某些情况下(尤其是在 Windows 上),由于某些库中内置了 DLL 加载,因此变得非常困难。有些人可能会尝试加载 DLL 的调试版本,有些人可能想要释放。这些不能都加载到同一进程中。
Debug versions are usually built with very few optimizations on -- therefore when you step through them in a debugger with source, there is a good chance that there is a good mapping between source line and what's going on in the program. When you step through highly optimized code, it doesn't map back to source very well, and is harder to debug.
Also, whenever someone uses an
#ifdef DEBUG
or equivalent, that code isn't there in the release version (of course). This could be extra error checking, logging, asserts, etc.Normally, the interface of the function shouldn't be different between debug and release, so you can normally link debug and release together without much trouble.
However, there are some cases (especially on Windows) that it becomes very difficult because of DLL loading built into some libs. Some may try to load debug versions of DLL's and some might want release. These can't both be loaded into the same process.