自动#defines根据在Visual Studio 2010中的Debug / Release配置 [英] Automatic #defines according to Debug/Release config in Visual Studio 2010

查看:163
本文介绍了自动#defines根据在Visual Studio 2010中的Debug / Release配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的程序中的调试输出像这样:

I have debug output in my program like this:

#ifdef DEBUG
    std::cout << "[RE_words] " << re << std::endl;
    try {
        boost::regex regex(re);
        std::cout << "[RE_words] " << "passed" << std::endl;
    } catch (exception& e) {
        std::cout << "[RE_words] " << "failed: " << e.what() << std::endl;
    }
#endif

DEBUG 在我的程序中手动定义。我总是注释掉行,当我做一个发布版本。在Visual Studio 2010中,还有用于处理用于编译的命令行等的 Debug vs 版本的配置。我也可以使用配置调试自动定义 DEBUG 到编译器?如何做?

and DEBUG is defined in my program manually. I always comment out the line when I make a release version. In Visual Studio 2010, there are also "Configuration"s 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.

这篇关于自动#defines根据在Visual Studio 2010中的Debug / Release配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆