Export to GitHub

google-glog - issue #33

Conflicts with windows.h


Posted on Feb 2, 2010 by Massive Ox

What steps will reproduce the problem? 1. #include <windows.h> 2. #include <glog/logging.h>

What is the expected output? What do you see instead? This generates: error C2059: syntax error : 'constant' error C2065: 'NUM_SEVERITIES' : undeclared identifier

whereas it would have been expected to compile cleanly.

What version of the product are you using? On what operating system? glog-0.3.0, Visual Studio 2005, Windows Vista 64 bit.

Please provide any additional information below.

Comment #1

Posted on Feb 8, 2010 by Massive Ox

The conflicts can be avoided by using #define NOGDI prior to including windows.h.

Comment #2

Posted on May 17, 2010 by Swift Kangaroo

WinGDI.h contains the following line:

define ERROR 0

which of course, eventually causes weird syntax errors.

The NOGDI solution should probably be documented, along with the fact that ERROR is not 0, and one should grep their code for possible misuse.

Those that need GDI should defines NOGDI then manually include the necessary headers with #undef ERROR afterward. NOGDI should still be defined to prevent other #includes from including WinGDI.h

Comment #3

Posted on May 28, 2010 by Massive Wombat

I added a small section into our document.

http://code.google.com/p/google-glog/source/detail?r=79

Thanks for discussions!

Comment #4

Posted on Nov 8, 2011 by Happy Kangaroo

WIN32_LEAN_AND_MEAN doesn't really help. Or at least not in all VC versions. I use MSVC 2008 and is included in out of the "WIN32_LEAN_AND_MEAN" section so, the only thing that works is NOGDI.

For reducing further confusing I propose adding the following section in log_severity.h (just before declaring severity constants):

ifdef _WIN32

ifdef ERROR

// If you see this warning then you included which tries to defines ERROR macro. To // avoid odd and unstable compile errors define a project wide macro NOGDI. // // Or if you plan using GDI at the very first line of the project add the following code: // //#include //#undef ERROR //#undef RGN_ERROR //#define RGN_ERROR 0

define STRING2(x) #x

define STRING(x) STRING2(x)

pragma message (FILE "(" STRING(LINE) ") : error: ERROR name has already been defined")

undef ERROR

endif /* ERROR */

endif /* _WIN32 */

This checking will catch the issue and produce nice VC-style error. Though, if one include windows.h after the logging.h there still be a problem. It probably makes sense to force definition of NOGDI right after the checking.

Comment #5

Posted on May 19, 2015 by Massive Kangaroo

Cam on

Status: Duplicate

Labels:
Type-Defect Priority-Medium