philsquared/Catch — Issue #65: catch.hpp with MinGW: error: '::OutputDebugStringA' has not been declared
Author: singbird
Created: 2011-12-23 13:48:34+00:00
State: open

Trying to compile the all-in-one header with MinGW 32-bit using GCC 4.6.1 results in the following error

catch.hpp: In function 'void writeToDebugConsole(const string&)':
catch.hpp:987:5: error: '::OutputDebugStringA' has not been declared

Looking back in the file, at lines 903 and 904 there is

#elif defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER)
#define CATCH_PLATFORM_WINDOWS

and starting at line 971 there is

#elif defined(_MSC_VER)
extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA( const char* );

Then in function writeToDebugConsole() there is

inline void writeToDebugConsole( const std::string& text )
{
#ifdef CATCH_PLATFORM_WINDOWS
::OutputDebugStringA( text.c_str() );
#else
// !TBD: Need a version for Mac/ XCode and other IDEs
std::cout << text;
#endif

So it seems OutputDebugStreamA() is defined only if using MSVC, but CATCH_PLATFORM_WINDOWS is defined even if not using MSVC. For now I simply commented out all but the std::cout << text; line in writeToDebugConsole() and it works fine.