Search code examples
c++visual-studio-2008tracerelease-builds

TRACE Macro Not Compiled Out Properly in Release Build - C++


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.


Solution

  • 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:

    _T(__FILE__)