C++ – What predefined macro can be used to detect debug build with clang

cclangdebugging

MSVC defines _DEBUG in debug mode, gcc defines NDEBUG in release mode. What macro can I use in clang to detect whether the code is being compiled for release or debug?

Best Answer

If you look at the project settings of your IDE, you will see that those macros are actually manually defined there, they are not automatically defined by the compiler. In fact, there is no way for the compiler to actually know if it's building a "debug" or "release", it just builds depending on the flags provided to it by the user (or IDE).

You have to make your own macros and define them manually, just like the IDE does for you when creating the projects.