Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflicts with windows.h #33

Closed
GoogleCodeExporter opened this issue Jan 28, 2016 · 5 comments
Closed

Conflicts with windows.h #33

GoogleCodeExporter opened this issue Jan 28, 2016 · 5 comments

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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

  • Changed state: Duplicate

@GoogleCodeExporter
Copy link
Author

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

@GoogleCodeExporter
Copy link
Author

Cam on

Original comment by huan767...@gmail.com on 19 May 2015 at 10:32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant