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?
C++ – What predefined macro can be used to detect debug build with clang
cclangdebugging
Related Topic
- .net – “The breakpoint will not currently be hit. The source code is different from the original version.” What does this mean
- What predefined macro can I use to detect clang
- Java – a stack trace, and how can I use it to debug the application errors
- C++ – Debug vs Release in CMake
- C++ – Why are elementwise additions much faster in separate loops than in a combined loop
- C# – System.Windows.Application.GetResourceStream returns null
- C++ – Detect gcc as opposed to msvc / clang with macro
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.