SDL2, Mac OS X and OpenGL: how to avoid including gl.h and gl3.h?

I am working on an SDL2 application using the main OpenGL 3.2 profile. When I compile, I get the following warning:

/System/Library/Frameworks/OpenGL.framework/Headers/gl.h/10-22: warning: #warning gl.h and gl3.h are both included. The compiler will not cause errors when using the remote OpenGL functionality. [-Wcpp]

I should assume that the SDL includes gl.h somewhere, because my only included in it are the following:

#define GL3_PROTOTYPES #include <OpenGL/gl3.h> #include <SDL2/SDL.h> 

Although I can simply ignore this, it already led to one hard-to-reach error when I accidentally used an enumeration value not available in the main profile. Is there a way to prevent gl.h from being included?

+6
source share
2 answers

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."

+11
source

This warning disappears in the candidate version 2.0.4 of SDL2. The Temp link for the release of the candidate has been published on the SDL mailing list. http://forums.libsdl.org/viewtopic.php?t=11305

+1
source

Source: https://habr.com/ru/post/954859/


All Articles