我在尝试使用 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
^
图形系统.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"
我不确定这是否可能是有意的。在触发警告的定义之上有一个定义,包含在 an#else
中#ifdef APIENTRY
。警告由以下原因触发:
#define GLEW_APIENTRY_DEFINED
#define APIENTRY // <-- Line 233 glew.h
这似乎与许多其他问题有关,但其中大部分都讨论了包含的顺序——这个顺序似乎应该基于它们起作用:
- 如何防止宏重新定义
- linux上的OpenGL库链接
- http://forums.codeguru.com/showthread.php?438957-Why-do-i-get-this-warning
- https://www.opengl.org/discussion_boards/showthread.php/163436-GLUT-and-macro-redefinition-errors
通常我不会对此感到太困扰,但由于 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 包是不是坏了?