Take a look at /System/Library/Frameworks/OpenGL.framework/Headers/gl.h , you will see that the defender is included in the standard standard in the first line: #ifndef __gl_h_ . If you look at gl3.h , you will notice that equally the standard includes protection for __gl3_h_ . This warning only fires when both are defined and GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED is undefined.
The easiest way to prevent everything inside gl.h from being included is #define __gl_h_ before it is included. To avoid messing up your actual code with something unpleasant, like this:
#ifdef __APPLE__ # define __gl_h_ # define GL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED #endif
I would suggest adding -D__gl_h_ -DGL_DO_NOT_WARN_IF_MULTI_GL_VERSION_HEADERS_INCLUDED as a compiler to your Makefile when you target OS X (so no matter where gl.h indirectly turned on, it never does anything). This is really the wrong way to solve this problem, and this warning was generated for some reason (which you indicated in your question - outdated OpenGL tokens will not generate compiler warnings / errors when both headers are included).
I think SDL2 itself must have some kind of pre-processor mechanism to do what I did above with #ifdef __APPLE__ , but instead it will do its job. This is not an error that allows you to include both, OS X simply provides a convenient mechanism for generating compiler errors when obsolete tokens (for example, GL_MODELVIEW ) are used in a project that should be a 3+ kernel.
On other platforms, regardless of whether you use the main OpenGL 3+, the compilation is not so black and white, so the compiler cannot be used for this purpose. This is one of those things that Apple does only because they can; "think differently."
source share