In a large C++/Qt/QMake/qtcreator project I would like to perform some tests, but only when I am compiling with the debug flag.
Is there a way to tell g++ that some small parts of the code have to be compiled only in debug mode ?
In a large C++/Qt/QMake/qtcreator project I would like to perform some tests, but only when I am compiling with the debug flag.
Is there a way to tell g++ that some small parts of the code have to be compiled only in debug mode ?
The standard way to do this is to depend on the macro
NDEBUG
, which is used by the macroassert()
defined in<cassert>
:The opposite of
#ifdef
is#ifndef
, and of course#else
branches are optional.If this macro doesn't work (for whatever reason), you
can try the macro
QT_NO_DEBUG
, which Qt uses for a similar purpose withQ_ASSERT()
; andshould fix it so that
NDEBUG
is (un)defined correctly; it's required for<cassert>
to work properly, and code you use may depend on it.