Automatic #defines according to Debug/Release config in Visual Studio(根据 Visual Studio 中的调试/发布配置自动#defines)
问题描述
我的程序中有这样的调试输出:
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).
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 中的调试/发布配置自动#defines的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:根据 Visual Studio 中的调试/发布配置自动#defines
基础教程推荐
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- CString 到 char* 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
