gitfredy / google-glog

Automatically exported from code.google.com/p/google-glog
Other
0 stars 0 forks source link

Conflicts with windows.h #33

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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.

Original issue reported on code.google.com by ragnar.c...@gmail.com on 2 Feb 2010 at 2:04

GoogleCodeExporter commented 9 years ago
The conflicts can be avoided by using #define NOGDI prior to including 
windows.h.

Original comment by ragnar.c...@gmail.com on 8 Feb 2010 at 3:06

GoogleCodeExporter commented 9 years ago
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

Original comment by jillian....@gmail.com on 17 May 2010 at 11:34

GoogleCodeExporter commented 9 years ago
I added a small section into our document.

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

Thanks for discussions!

Original comment by shinichi...@gmail.com on 28 May 2010 at 3:23

GoogleCodeExporter commented 9 years ago
WIN32_LEAN_AND_MEAN doesn't really help. Or at least not in all VC versions. I 
use MSVC 2008 and <wingdi.h> is included in <windows.h> 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 <windows.h> 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 <windows.h>
//#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.

Original comment by rea...@gmail.com on 8 Nov 2011 at 7:19