C++ MSYS2上的GLEW APIENTRY警告和可能的相关错误

C++ MSYS2上的GLEW APIENTRY警告和可能的相关错误,c++,windows,opengl,glew,msys2,C++,Windows,Opengl,Glew,Msys2,我在尝试使用MSYS2的SDL2/GLEW/OpenGL时收到一个令人困惑的编译器错误: In file included from /m/gstest/inc/graphics/GraphicsSystem.h:36:0, from /m/gstest/src/main.cpp:1: /c/msys64/mingw64/include/GL/glew.h:233:0: warning: "APIENTRY" redefined #define APIENTR

我在尝试使用MSYS2的SDL2/GLEW/OpenGL时收到一个令人困惑的编译器错误:

In file included from /m/gstest/inc/graphics/GraphicsSystem.h:36:0,
                 from /m/gstest/src/main.cpp:1:
/c/msys64/mingw64/include/GL/glew.h:233:0: warning: "APIENTRY" redefined
 #define APIENTRY
 ^
In file included from /usr/include/w32api/windef.h:8:0,
                 from /m/gstest/inc/graphics/GraphicsSystem.h:33,
                 from /m/gstest/src/main.cpp:1:
/usr/include/w32api/minwindef.h:103:0: note: this is the location of the previous definition
 #define APIENTRY WINAPI
 ^
GraphicsSystem.h:

// Must come before glew
#include <windef.h>

// Must come before OpenGL (SDL)
#include "glew.h"
//#include "glxew.h"
//#include "wglew.h"

#include "SDL.h"
#include "SDL_opengl.h"
#include "SDL_syswm.h"
这似乎与许多其他问题有关,但大多数问题都讨论了包含的顺序——这个顺序似乎应该基于这些问题:

通常情况下,我不会对此感到太麻烦,但由于SDL包含的头文件中似乎存在APIENTRY的问题,我也会遇到阻止构建的错误。例如:

In file included from /usr/include/w32api/winbase.h:15:0,
                 from /usr/include/w32api/windows.h:70,
                 from /c/msys64/mingw64/include/SDL2/SDL_opengl.h:40,
                 from /m/gstest/inc/graphics/GraphicsSystem.h:41,
                 from /m/gstest/src/main.cpp:1:
/usr/include/w32api/debugapi.h:27:31: error: expected initializer before 'Contin
ueDebugEvent'
   WINBASEAPI WINBOOL APIENTRY ContinueDebugEvent (DWORD dwProcessId, DWORD dwThreadId, DWORD dwContinueStatus);
                               ^
这似乎是一个不寻常的巧合,因为我很少有这样的问题,只有警告和错误在一起


为什么glew.h会有第二组
#defines
,覆盖以前的
#defines
,当它到达防止破坏它们的末端时(出于正当理由)?这似乎注定会导致今后的错误。我的glew软件包是否已损坏?

这似乎是由于此版本/构建的g++未定义
\u WIN32
,这导致glew遍历预处理器指令的Unix分支,从而破坏了APIENTRY定义。因此,这实际上根本不是GLEW的问题


显然,尽管我对它的智慧持怀疑态度。正确的解决方案是将
-mwin32
添加到编译器标志中。这将声明
\u WIN32
为正常,并避免Unix样式库对其平台产生混淆。

奇怪的是,您使用的是/usr/include(基于msys-2.0.dll的工具链)的头,也使用/mingw64/include(mingw-w64工具链)的头。这些工具链不应该是混合和匹配的;你应该选一个并坚持下去。如果可以的话,我建议您使用mingw-w64,因为它编译的本机Windows二进制文件不需要msys-2.0.dll提供的POSIX仿真。
In file included from /usr/include/w32api/winbase.h:15:0,
                 from /usr/include/w32api/windows.h:70,
                 from /c/msys64/mingw64/include/SDL2/SDL_opengl.h:40,
                 from /m/gstest/inc/graphics/GraphicsSystem.h:41,
                 from /m/gstest/src/main.cpp:1:
/usr/include/w32api/debugapi.h:27:31: error: expected initializer before 'Contin
ueDebugEvent'
   WINBASEAPI WINBOOL APIENTRY ContinueDebugEvent (DWORD dwProcessId, DWORD dwThreadId, DWORD dwContinueStatus);
                               ^