Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unwanted header file WinGDI.h

I am doing some macros like

#define report_msg(type,msg_str).......my_special_##type(......)

#define report_error(msg_str) report_msg(ERROR,msg_str)

It works perfect under linux while when I compile with visual studio 2010 express, I see it gives error that

error C3861: 'my_special_0': identifier not found

The reason is that "ERROR" is interpreted as 0. And when I use "Go to defination" in MSVC, it goes to WinGDI.h

/* Region Flags */
#define ERROR 0

Question is why this WinGDI.h is included? How can I eliminated it without touching the code?

like image 287
thundium Avatar asked Nov 21 '14 15:11

thundium


2 Answers

Solution 1: Swap include orders of some headers -> tedious task

Solution 2: Put NOGDI in preprocessor. In Visual Studio: Project Properties -> Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions -> add NOGDI.

Explanation: Paul pointed me in the right direction. I don't use precompiled headers, so I don't include stdafx.h. My problem is related to Linux vs. Windows libraries.

In my case I use a library, which defines the constant 'ERROR' for log messages. For timestamps ctime.h is included, which uses Windows.h/WinGDI.h.

like image 102
Thomas Wilde Avatar answered Oct 06 '22 15:10

Thomas Wilde


This is why macros are evil. I've seen cases where TRUE and FALSE are defined with different values in different headers. In any project of decent size it may become tedious to follow the chains of headers. Try

#undef ERROR 

#define report_msg(type,msg_str).......my_special_##type(......)
#define report_error(msg_str) report_msg(ERROR,msg_str)

and hope that the "real" definition of ERROR is not needed after these statements.

like image 20
Oncaphillis Avatar answered Oct 06 '22 14:10

Oncaphillis