Skip to content

fix(build): hoist GL_GLEXT_PROTOTYPES out of __APPLE__ branch#7

Open
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:fix/gl-glext-prototypes-linux
Open

fix(build): hoist GL_GLEXT_PROTOTYPES out of __APPLE__ branch#7
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:fix/gl-glext-prototypes-linux

Conversation

@DTW-Thalion
Copy link
Copy Markdown

Problem

On Linux with clang 16+ (clang 18.1.3 on Ubuntu 24.04), building Source/CARenderer.m fails with:

CARenderer.m:451:11: error: call to undeclared function 'glUseProgram';
  ISO C99 and later do not support implicit function declarations

and a handful of similar errors for other GL 2.0+ entry points.

Root cause

Source/CABackingStore.h sets GL_GLEXT_PROTOTYPES only inside the __APPLE__ branch:

#if (__APPLE__)
#define GL_GLEXT_PROTOTYPES 1
#import <OpenGL/OpenGL.h>
#import <OpenGL/gl.h>
#import <OpenGL/glu.h>
#else
#import <GL/gl.h>    // no GL_GLEXT_PROTOTYPES defined here!
#import <GL/glu.h>
#endif

On Linux, <GL/gl.h> then transitively includes <GL/glext.h> — but since GL_GLEXT_PROTOTYPES isn't set at that point, glext.h sets its own include guard __gl_glext_h_ without emitting any OpenGL 2.0+ prototype declarations. CARenderer.m's later #import <GL/glext.h> with GL_GLEXT_PROTOTYPES set is then a no-op because of the guard, and glUseProgram and friends end up as implicit declarations.

Older clang (≤15) treated implicit declarations as a warning; clang 16 promoted it to an error by default, which is what finally surfaced the latent bug.

Fix

Move #define GL_GLEXT_PROTOTYPES 1 above the __APPLE__ split, so every backend has it set before the first time any glext.h is traversed. All OpenGL 2.0+ prototypes are then emitted on first entry, and the later glext.h imports in CARenderer.m continue to work.

Platform impact

  • Linux/Mesa: CARenderer.m now compiles cleanly against clang 16+ and Mesa's headers.
  • macOS: unchanged — the #define was already set on this path; hoisting it is a no-op.
  • Windows: unchanged — current MSYS2 clang builds don't go through this include chain.

Test plan

  • Ubuntu 24.04 + clang 18.1.3 + Mesa libgl1-mesa-dev 25.2: libs-quartzcore framework builds cleanly
  • Verified preprocessor output: glUseProgram, glCreateShader, glLinkProgram, glGetUniformLocation etc. are all declared at the point of use
  • macOS spot-check (don't have a Mac; the changed line is platform-agnostic)

CABackingStore.h only set GL_GLEXT_PROTOTYPES inside the __APPLE__
branch. On Linux (and every other non-Apple platform), <GL/gl.h> was
imported without the define, then it transitively included
<GL/glext.h> which set its include guard without emitting any
OpenGL 2.0+ prototypes. CARenderer.m's later import of <GL/glext.h>
was then a no-op, so glUseProgram and friends ended up as implicit
declarations — an error under clang 16+.

Move the define above the platform split so every backend gets
prototypes emitted on first glext.h traversal.

No behavioral change on Windows or macOS; Linux now compiles cleanly
against Mesa.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@DTW-Thalion DTW-Thalion requested a review from ivucica as a code owner April 13, 2026 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant