C++ 调试版本和发布版本是什么意思,区别和用途

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11883074/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 15:39:44  来源:igfitidea点击:

what does mean by debug build and release build, difference and uses

c++debuggingbuildreleasewxwidgets

提问by Natwar Singh

Possible Duplicate:
Debug/Release difference

可能的重复:
调试/发布差异

I want to know what do these two mean: Debug build and Release build and what is the difference between both.

我想知道这两个是什么意思:调试构建和发布构建以及两者之间的区别是什么。

Which one should I use (I mean which are the suitable conditions for each one) and which build actually I am using now if I make a simple C++ project in Visual studio. [If I do not change any projects settings]

如果我在 Visual Studio 中创建一个简单的 C++ 项目,我应该使用哪个(我的意思是每个人的合适条件)以及我现在正在使用的实际构建。[如果我不更改任何项目设置]

I am asking this because I am trying to make a GUI using wxWidgets 2.9.4 and they give different case of adding required .lib. these are

我问这个是因为我正在尝试使用 wxWidgets 2.9.4 制作 GUI,并且他们给出了添加所需 .lib 的不同情况。这些是

release ANSI static

release ANSI static

debug ANSI static

debug ANSI static

release Unicode static

release Unicode static

debug Unicode static

debug Unicode static

Please put a detailed answer.

请给出详细的答案。

回答by James Kanze

Debug build and release build are just names. They don't mean anything.

调试构建和发布构建只是名称。他们没有任何意义。

Depending on your application, you may build it in one, two or more different ways, using different combinations of compiler and linker options. Mostapplications should only be build in a single version: you test and debug exactly the same program that the clients use. In some cases, it may be more practical to use two different builds: overall, client code needs optimization, for performance reasons, but you don't want optimization when debugging. And then there are cases where full debugging (i.e. iterator validation, etc.) may result in code that is too slow even for algorithm debugging, so you'll have a build with full debugging checks, one with no optimization, but no iterator debugging, and one with optimization.

根据您的应用程序,您可以使用编译器和链接器选项的不同组合,以一种、两种或多种不同的方式构建它。 大多数应用程序应该只构建在一个版本中:您测试和调试客户端使用的完全相同的程序。在某些情况下,使用两种不同的构建可能更实用:总体而言,出于性能原因,客户端代码需要优化,但您在调试时不需要优化。然后在某些情况下,完整调试(即迭代器验证等)可能会导致代码即使对于算法调试也太慢,因此您将拥有一个带有完整调试检查的构建,一个没有优化,但没有迭代器调试,和一个优化。

Anytime you start on an application, you have to decide what options you need, and create the corresponding builds. You can call them whatever you want.

任何时候开始应用程序时,您都必须决定需要哪些选项,并创建相应的构建。您可以随心所欲地称呼他们。

With regards to external libraries (like wxwidgets): all compilers have some incompatibilities when different options are used. So people who deliver libraries (other than in source form) have to provide several different versions, depending on a number of issues:

关于外部库(如 wxwidgets):当使用不同的选项时,所有编译器都有一些不兼容性。因此,交付库(而不是源代码形式)的人必须提供几个不同的版本,具体取决于许多问题:

  • release vs. debug: the release version will have been compiled with a set of more or less standard optimization options (and no iterator debugging); the debug version without optimization, and with iterator debugging. Whether iterator debugging is present or not is one thing which typically breaks binary compatibility. The library vendor should document which options are compatible with each version.

  • ANSI vs. Unicode: this probably means narrow charvs wide wchar_tfor character data. Use which ever one corresponds to what you use in your application. (Note that the difference between these two is much more than just some compiler switches. You often need radically different code, and handling Unicode correctly in all cases is far from trivial; an application which truly supports Unicode must be aware of things like composing characters or bidirectional writing.)

  • static vs. dynamic: this determines how the library is linked and loaded. Usually, you'll want static, at least if you count on deploying your application on other machines than the one you develop it on. But this also depends on licensing issues: if you need a license for each machine where the library is deployed, it might make more sense to use dynamic.

  • 发布与调试:发布版本将使用一组或多或少的标准优化选项进行编译(并且没有迭代器调试);没有优化的调试版本,并带有迭代器调试。迭代器调试是否存在通常是破坏二进制兼容性的一件事。库供应商应该记录哪些选项与每个版本兼容。

  • ANSI 与 Unicode:这可能意味着 字符数据的窄char与宽wchar_t。使用与您在应用程序中使用的内容相对应的任何一个。(请注意,这两者之间的区别不仅仅是一些编译器切换。您经常需要完全不同的代码,并且在所有情况下正确处理 Unicode 绝非易事;真正支持 Unicode 的应用程序必须了解诸如组合字符之类的事情或双向写入。)

  • 静态与动态:这决定了库的链接和加载方式。通常,您需要静态,至少如果您指望将应用程序部署在其他机器上而不是您开发它的机器上。但这也取决于许可问题:如果您需要为部署库的每台机器获得许可,使用动态可能更有意义。

回答by Some programmer dude

When doing a DEBUGbuild the project is set up to not optimize (or only verylightly optimize) the generated code, and to tell the compiler to add debug information (which includes information about functions, variables, and other information needed for debugging). The pre-processor is set up to define the _DEBUGmacro.

当进行DEBUG构建的项目设置为不优化(或只有非常轻微优化)生成的代码,并告诉编译器添加调试信息(包括有关函数,变量和调试所需的其他信息)。预处理器被设置为定义_DEBUG宏。

A RELEASEbuild on the other hand have higher level of optimization, and no debug information is saved. The pre-processor is set up to define the NDEBUGmacro.

一个RELEASE在另一方面构建具有优化的更高水平,并没有调试信息保存。预处理器被设置为定义NDEBUG宏。

Another difference is that certain "system" macros, for example ASSERT-like macros, do different things depending on if _DEBUGor NDEBUGis defined. ASSERTdoes nothing in a release build, but does checks and abort in debug builds.

另一个区别是某些“系统”宏,例如ASSERT-like 宏,根据 if_DEBUGNDEBUGis 定义做不同的事情。ASSERT在发布版本中什么都不做,但在调试版本中进行检查和中止。

The difference between Unicodeand non-Unicodeis mostly the UNICODEpre-processor macro, which tells header files if certain Unicode functionality should be enabled or not. One thing is that TCHARwill be defined to wchar_tin Unicode builds but as charin non-Unicode builds.

Unicode和非之间的区别Unicode主要是UNICODE预处理器宏,它告诉头文件是否应该启用某些 Unicode 功能。一件事是TCHARwchar_t在 Unicode 构建中定义为,但char在非 Unicode 构建中定义。

回答by ravenspoint

In the debug build you get a lot more error checjking, so if something goes wrong you may get a more informative message ( and it will run more slowly )

在调试版本中,您会得到更多的错误检查,因此如果出现问题,您可能会收到更多信息(并且运行速度会更慢)

In the debug build you will get more information when you run it under the debugger.

在调试版本中,当您在调试器下运行它时,您将获得更多信息。

You can tell if the build is debug build by looking at the preprocessor definitions of the project properties: _DEBUG will be defined.

您可以通过查看项目属性的预处理器定义来判断构建是否为调试构建:_DEBUG 将被定义。

You will send the release build to your clients. ( The debug build uses the debug libraries which are not present on most non development machines )

您将发布版本发送给您的客户。(调试版本使用大多数非开发机器上不存在的调试库)

回答by Tobias Langner

if you want to link a static library to a project, it needs to be compiled with the same settings that you use to compile your code. That's why there is a Debug & a Release version of the library. Additionally, you need to specify whether you want to use unicode or ansi. Here the answer is quite simple (in my opinion) - just use unicode.

如果要将静态库链接到项目,则需要使用与编译代码相同的设置对其进行编译。这就是为什么有一个 Debug 和一个 Release 版本的库。此外,您需要指定是要使用 unicode 还是 ansi。这里的答案很简单(在我看来) - 只需使用 unicode。

What is different in Release compared to Debug so that they can't mix? Mainly it's the memory management. The memory management in Debug does a lot of additional things to allow you to find errors early. As an example, there are canaries that can be checked for overwriting of code. Uninitialized memory is initialized with a specific pattern, ... Additionally, there are a lot of optimizations in release that are not used in debug. This allows release to run faster but makes it difficult to debug the code. Methods might get optimized away and instead are inlined, the parameter passing may be optimized to use registers, ...

与 Debug 相比,Release 有什么不同,因此它们不能混合?主要是内存管理。Debug 中的内存管理做了很多额外的事情来让你及早发现错误。例如,有可以检查代码覆盖的金丝雀。未初始化的内存是用特定的模式初始化的,......此外,发布中有很多优化没有在调试中使用。这允许发布运行得更快,但难以调试代码。方法可能会被优化掉,而是被内联,参数传递可能会被优化为使用寄存器,...

So in C++ you manage (at least) 2 configurations. One Debug configuration that you link with the debug library. This one is for developing & testing. And a Release configuration linked with the release library. This one is for delivery. But don't forget that you need to test Release as well as it might behave differently than the Debug configuration.

因此,在 C++ 中,您管理(至少)2 个配置。您与调试库链接的一种调试配置。这是用于开发和测试的。以及与发布库链接的发布配置。这个是用来送货的。但是不要忘记您需要测试 Release 以及它的行为可能与 Debug 配置不同。