Tharanga
Tharanga

Reputation: 2117

executing Debug vs release builds in Qt

Can some one explain other than the debugging symbols being embedded in the debug build, if there is any other difference. Further I am very curious as to know how they differ in executing binary. What mechanisms are being used use debug symbols in the debug build show the errors.

Upvotes: 4

Views: 3962

Answers (2)

Martin
Martin

Reputation: 4862

Compiling as debug in qt sets for one thing the -DQT_NO_DEBUG flag in the compiler call which is used in many qt libraries. As Jimmy already pointed out, the main performance difference comes from this source. One extreme example could be the use of a debug version of STL containers that can be used to check boundaries. If this is used in your code in debug mode things may take a lot longer (Qt does not use this one but introduces similar checks on its libraries).

Further usually the optimization flags are changed. For release -O2 is chosen for release and not optimization for debug

One more important thing about the debug build is that you can use it to trigger different things in a pro file, like adding defines, changing the target or compiling against another set of libraries:

CONFIG(debug, debug|release) {
  message("Debug")
  DESTDIR = $$DESTDIR-debug
  CONFIG += debug
  DEFINES += DEBUG
  TARGET = $$TARGET-debug
}else{
  message("Release")  
  DEFINES += QT_NO_DEBUG_OUTPUT
  DESTDIR = $$DESTDIR-release
  TARGET = $$TARGET-release
}

If you're interested in more details take a look at the qmake configuration files. Linux Ubuntu: /usr/share/qt4/mkspecs/common/g++.conf /usr/share/qt4/mkspecs/common/linux.conf and the target dependent conf files

Upvotes: 3

Frank Osterfeld
Frank Osterfeld

Reputation: 25165

The exact definition and behavior of a "release build" vs. a "debug build" depends on the build system and the compiler you use. Some common properties of release builds compared to debug builds:

  • debug builds usually generate debug information, release builds not. There are some hybrids though, like release builds with separate debug information.
  • Assertions are not evaluated (assert(p = getFoo()); won't assign anything - nor assert). So expressions with side-effects inside asserts are a bad idea.
  • The optimization settings are usually different (no or few optimizations in debug builds)
  • debug output might be suppressed
  • Any library developer might additionally implement different behavior depending on e.g. the NDEBUG preprocessor macro

Upvotes: 1

Related Questions