Without adding special -D build options, is there a means to determine if a build is a 'Debug' or 'Release', as set by the Configuration Manager? I've tried ifdeffing 'NDEBUG' or '_DEBUG', but it appears they are not automatically defined, and thus referencing either is unproductive. The user simply wants to know if a build is 'release' or 'debug' on startup, likely so they'll know on which version to run automated performance tests. There's the configuration property $(Configuration), but how to reference that programmatically is a puzzle, assuming it can be done at all. Perhaps the optimization level (/Ox) can be checked...somehow. Anyway, perhaps it's just not possible and the user will just have to assume. I've looked at other questions, but as they don't seem to mesh very well with this difficulty, I thought I'd toss it in, see what happens. I told him that if they can check the executable size, well, 'debug' is twice the size of 'release'; they didn't care much for that notion. Thanks.
Asked
Active
Viewed 3,901 times
-1
-
3You should be able to count on `_DEBUG`. See https://stackoverflow.com/a/367922/434551. – R Sahu Aug 09 '17 at 18:53
-
Thanks for the prompt responses. The version with #ifdef _DEBUG output the same eyecatcher (blah Release mm/dd/yy) whether debug or release build. The user's tests check a startup message – Lark Aug 09 '17 at 18:59
-
I am surprised by that. – R Sahu Aug 09 '17 at 19:02
-
...sorry, hit the enter key. The user's tests inspect a startup message and that determines what sort of tests they'll run. As mentioned earlier, I checked other entries, and that's why I tried '_DEBUG' and 'NDEBUG', to no effect. The debug build is indeed a debug build, and the optimized release build is indeed an optimized release build. I made the mistake of thinking this was a simple change, and now, as always, it has metastasized. – Lark Aug 09 '17 at 19:02
-
Actually, I made the mistake of telling the user that it was a simple change. – Lark Aug 09 '17 at 19:04
-
Here's the C++-specific build line: /GS /GL /W3 /Gy /Zc:wchar_t /Zi /Gm- /Ox /Fd"x64\Release\vc140.pdb" /Zc:inline /fp:precise /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /Gd /Oi /MT /Fa"x64\Release\" /EHsc /nologo /Fo"x64\Release\" /Fp"x64\Release\blah.pch" – Lark Aug 09 '17 at 19:07
-
...and the debug build line: /GS /W3 /Zc:wchar_t /ZI /Gm /Od /Fd"x64\Debug\vc140.pdb" /Zc:inline /fp:precise /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /Gd /Oi /MT /Fa"x64\Debug\" /EHsc /nologo /Fo"x64\Debug\" /Fp"x64\Debug\blah.pch" – Lark Aug 09 '17 at 19:08
-
...which probably is no help at all. But there you go. – Lark Aug 09 '17 at 19:09
-
I'm out of my depth here. Hope someone else can help you. – R Sahu Aug 09 '17 at 19:16
1 Answers
2
Beyond checking a define at compile time (like NDEBUG
or _DEBUG
or some other define you set yourself) and outputting a message based on that, then the answer is "No, you cannot generally determine programatically at run time how the executable was compiled".
But it's fairly easy to do at compile time:
#if defined _DEBUG
std::cout << "debug build\n";
#else
std::cout << "release build\n";
#endif
Then just make sure your build system sets whatever define you base your check on.. shouldn't take long to do.

Jesper Juhl
- 30,449
- 3
- 47
- 70