TRACE 宏在发布版本中未正确编译 - C++
当我对 Visual Studio 2008 解决方案进行发布构建时,我收到一堆如下错误:
错误 C2059:语法错误:','
这是我通常使用 TRACE
的方式:
TRACE(_T("My error message.\r\n\tError: %d\r\n\tFile: %s\r\n\tLine: %d\r\n"), ::GetLastError(), __WFILE__, __LINE__);
还有一个实例,我将它与 5 个参数一起使用。
我认为 TRACE 应该为发布版本完全编译出来。我需要做什么才能使其编译完成?谢谢。
When I do a Release build of my Visual Studio 2008 solution I get a bunch of errors like this:
error C2059: syntax error : ','
This is how I typically use TRACE
:
TRACE(_T("My error message.\r\n\tError: %d\r\n\tFile: %s\r\n\tLine: %d\r\n"), ::GetLastError(), __WFILE__, __LINE__);
There is also an instance where I use it with 5 parameters.
I thought TRACE
was suppose to compile out completely for Release builds. What do I need to do to make it compile out complete? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
__WFILE__
宏的定义导致了问题。有两种方法可以解决这个问题。首先,您可以定义宏,如下所示:http ://msdn.microsoft.com/en-us/library/b0084kay(v=vs.80).aspx
请注意,它们不会将宏包装在
#ifdef _DEBUG
中,这这是有道理的,因为相应的 __FILE__ 宏在发布模式下也不会被删除。但该文档适用于 VS2005。它已从新版本的文档中删除。这就是您可能想要这样做的原因:
The definition of your
__WFILE__
macro is causing the problem. There are two ways to solve this. First, you can define the macro as shown here:http://msdn.microsoft.com/en-us/library/b0084kay(v=vs.80).aspx
Note they don’t wrap the macro in
#ifdef _DEBUG
, which makes sense since the corresponding__FILE__
macro is not removed in release mode either.But that documentation is for VS2005. It’s been removed from newer versions of the documentation. That’s why you may want to do this:
首先,据我所知,它是
__FILE__
,而不是__WFILE__
。这就是为什么你会收到逗号错误。由于预处理器无法找到它。二、为什么每个TRACE中都写最后三个参数? TRACE 是一个宏,对吧?
所以你可以这样定义它:(另请参阅define
__WFILE__
宏)现在,你可以像这样TRACE
你就完成了!
First of all, it's
__FILE__
as far as I know, not__WFILE__
. that is why you get that comma error. Since preprocessor is unable to find it.Second, why do you write the last three parameters in each TRACE? TRACE is a MACRO, right?
So you can define it like this: (also see the define
__WFILE__
macro)Now, you can TRACE like this
And you're done!