views:

88

answers:

5

Hi all, after working some time in my project, this warning begin to appear:

2>Game.cpp
2>c:\program files\microsoft sdks\windows\v6.0a\include\windef.h(126) : warning C4005: 'APIENTRY' : redefinición de macro
2>        c:\users\ferran\directo\gameprojects\dev-libs\glfw\include\glfw.h(72) : vea la definición anterior de 'APIENTRY'
2>c:\program files\microsoft sdks\windows\v6.0a\include\wingdi.h(23) : warning C4005: 'WINGDIAPI' : redefinición de macro
2>        c:\users\ferran\directo\gameprojects\dev-libs\glfw\include\glfw.h(88) : vea la definición anterior de 'WINGDIAPI'

I'm sure that is a matter of the order of the include files to solve, because none of this files are mine. My question is if there is a generic way to prevent or to find which files must to be reordered to avoid this message.

+5  A: 

The problem is in the file Game.cpp. Try to include windows.h before glfw.h. There is a guard in glfw.h which will prevent that warning:

#ifndef APIENTRY
 #ifdef _WIN32
  #define APIENTRY __stdcall
 #else
  #define APIENTRY
 #endif
 #define GL_APIENTRY_DEFINED
#endif // APIENTRY
tibur
+1  A: 

The error message itself is telling you the incorrect order. It says that windef.h and wingdi.h are redefining symbols that were defined in glfw.h.

Put glfw.h after the Windows include files.

Mark Ransom
That is a very good answer, because is a general solution or at least a good starting point to solve these type of problems.
Killrazor
+1  A: 

Unfortunately or fortunately, no. There is no such tool that automates it. You have to go read the code in those header files, figure out what is going on and take appropriate actions.

The most you can do is

  1. Check if macro is defined using ifdef or if defined(...) or if !defined(...) preprocessor constructs.
  2. Undefine macro using undef.

Only ANSI C considers macro redefinition an error.

Vlad Lazarenko
+1  A: 

Microsoft doesn't generally design headers to be free-standing. Most of the Windows-oriented headers require that you have first included <windows.h>. Except except for the dependency on that Mother Of All Headers, usually there are no specific header dependencies so by including <windows.h> first you shouldn't have any problem.

Cheers & hth.

Alf P. Steinbach
+1  A: 

This may be caused by Visual Studio pre-compiling headers for you. Be sure that all standard and microsoft headers are included before yours. Don't include microsoft headers in any of your .h files (it looks like you have windef.h and wingdi.h inlcuded in your glfw.h). Be sure that all your headers are side-effect free. The problem should then go away. Figuring out exactly what is causing it is generally very hard.

verisimilidude