C++ determine if compiling with debug symbols without defining a preprocessor symbol

cdebugginggcc

I have been using something like this:

int main(int argc, char *argv[])
{

#ifdef DEBUG
    printf("RUNNING DEBUG BUILD");
#else
    printf("Running... this is a release build.");
#endif
...

However this requires me to compile with -DDEBUG for the debug build. Does GCC give me some way for me to determine when I am compiling with debug symbols (-g flag) such as defining its own preprocessor macro that I can check for?

Best Answer

Answer is no. Usually these macros (DEBUG, NDEBUG, _DEBUG) are set by the IDE/make system depending on which configuration (debug/release) you have active. I think these answers can be of help:

C #define macro for debug printing

Where does the -DNDEBUG normally come from?

_DEBUG vs NDEBUG