Detailed explanation of the difference between Debug and Release released by the project

  • 2021-12-09 10:02:58
  • OfStack

This article explains the difference between Debug and Release released by the project for your reference. The specific contents are as follows

1. Differences between Debug and Release

Debug: Debug version, contains debug information, so much larger than Release, and without any optimization (optimization will complicate debugging, because the relationship between source code and generated instructions will be more complex), easy for programmers to debug. Two files are generated in Debug mode. In addition to the. exe or. dll files, there is also a. pdb file that records debugging information such as code breakpoints

Release: Release, do not debug the source code, compile time to optimize the speed of the application, so that the program in code size and running speed are optimal. (Debugging information can be generated in a separate PDB file). Generate 1 file in Release mode. exe or. dll file

2. The role of the Obj folder

obj directory also has two subdirectories, debug and release. obj directory is the source directory for the project to generate dll, and then copy the generated dll to bin directory. obj is used to store intermediate temporary files generated during compilation. In. Net, when modules are compiled, the compilation results of each module are saved in the obj directory, and finally merged into one. exe or. dll file and saved in the bin directory.

Because each compilation is incremental, that is, only the changed modules are recompiled, the function of this obj directory is to save the compilation results of these small blocks and speed up the compilation.

3. Essential differences between Debug and Release compilation methods

Often called the debug version, Debug contains debug information and is not optimized to make it easier for programmers to debug programs. Release is called a release version, and it is often optimized to make the program optimal in code size and running speed, so that users can use it well.
The real secret of Debug and Release lies in a set of compilation options. The options for each of the two are listed below. (Of course, there are other ones, such as/Fd/Fo, but the difference is not important, and usually they will not cause errors in Release, which is not discussed here.)

Debug version:

/MDd/MLd or/MTd Use Debug runtime library (runtime library for debug version)
/Od Turn off Optimization Switch
/D "_ DEBUG" is equivalent to # define _ DEBUG, turn on the compile and debug code switch (mainly for assert functions)
/ZI Create an Edit and continue (Edit Continue) database so you don't need to recompile if you modify the source code during debugging
/GZ can help catch memory errors
/Gm Turn on Minimum Relink Switch to Reduce Link Time

Release version:

/MD/ML or/MT Use the release version of the runtime function library
/O1 or/O2 Optimize Switches to Minimize or Fastest Programs
/D "NDEBUG" Turns off the conditional compile debug code switch (that is, does not compile assert functions)
/GF Merge duplicate strings and place string constants in read-only memory to prevent modifications

In fact, Debug and Release have no essential boundaries, they are just a collection of one set of compilation options, and the compiler only acts according to the predetermined options. In fact, we can even modify these options to get an optimized debug version or a release version with trace statements.

4. Appendix:

The Disaster of DLL

People call the mixed versions of DLL "the hell of dynamic link libraries" (DLL Hell), and even Microsoft itself says so.

If your program uses your own DLL, please note:

You cannot mix debug and release versions of DLL in 1. debug is debug version, and release version is release version.

The solution is to place the debug and release programs in the debug and release directories of the main program, respectively

Therefore, in the actual production environment, try to use the Release version of DLL.


Related articles: