what does mean by debug build and release build, difference and uses [duplicate]

隐身守侯 提交于 2020-01-10 03:15:09

问题


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]

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

release ANSI static

debug ANSI static

release Unicode static

debug Unicode static

Please put a detailed answer.


回答1:


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. Most applications 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:

  • 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 char vs wide wchar_t for 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.




回答2:


When doing a DEBUG build the project is set up to not optimize (or only very lightly 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 _DEBUG macro.

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

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

The difference between Unicode and non-Unicode is mostly the UNICODE pre-processor macro, which tells header files if certain Unicode functionality should be enabled or not. One thing is that TCHAR will be defined to wchar_t in Unicode builds but as char in non-Unicode builds.




回答3:


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.

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 )




回答4:


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.

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, ...

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.



来源:https://stackoverflow.com/questions/11883074/what-does-mean-by-debug-build-and-release-build-difference-and-uses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!