问题描述
我的程序中有如下调试输出:
I have debug output in my program like this:
#define DEBUG
...
#ifdef DEBUG
std::cout << "[RE_words] " << m_re << std::endl;
#endif
和DEBUG
是在我的程序中手动定义的.在发布发行版时,我总是会注释掉该行.在Visual Studio中,还有 Debug 和 Release 版本的配置,这些配置可以处理用于编译的命令行等.我还可以使用配置调试"为编译器自动定义DEBUG
吗?怎么样?
and DEBUG
is defined in my program manually. I always comment out the line when I make a release version. In Visual Studio, there are also Configurations for Debug vs Release versions which handle the commandline etc. used for compiling. Can I also use the Configuration "Debug" to automatically define DEBUG
to the compiler? How?
推荐答案
Visual Studio自动为Debug版本(对于非调试版本,为NDEBUG)定义_DEBUG符号.
The Visual Studio automatically defines _DEBUG symbol for Debug builds (and NDEBUG for non-debug builds).
另一种方法是转到项目设置->配置属性-> C/C ++->预处理程序,然后手动编辑预处理程序定义.
Another way to do this is to go to the project settings -> configuration properties -> C/C++ -> preprocessor, and edit the preprocessor definitions manually.
另请参阅:
此答案更详细地说明了_DEBUG和NDEBUG之间的区别.
此答案解释了NDEBUG符号的用途以及该符号是否由标准定义.
See also:
This answer explains the differences between _DEBUG and NDEBUG in more detail.
This answer explains the purpose of the NDEBUG symbol and whether or not is it defined by the standard.
这篇关于根据Visual Studio中的“调试/发布"配置自动#define的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!