Mac compilation error

Create issue
Issue #33 resolved
Lorcán Mc Donagh created an issue

Compilation fails on the definition of GLhandleARB which is defined as

typedef unsigned int GLhandleARB; 

in glLoadGen and as

typedef void* GLhandleARB

in Apple OpenGL framework (gltypes.h)

A simple


switch solves the problem.

Comments (13)

  1. Lorcán Mc Donagh reporter

    Actually I'm not including it directly, it gets included by adding a dependency to the OpenGL framework (rough equivalent of a lib under XCode) which is needed to link to OpenGL.

  2. Lorcán Mc Donagh reporter

    I tried it and as expected I get the following error:

    Attempt to include auto-generated header after gltypes.h

    However a Cocoa Mac OpenGL application needs to include the Cocoa framework (which in turn includes the system GL headers) to compile, so I don't think this approach can work.

    Modifying glspec.lua to conditionally change the typedef to match the one used in Mac gltypes.h works for me. Do you want me to submit a patch ?

  3. Jason McKesson repo owner

    This is the solution GLEW used to solve the same problem (since GLEW and glLoadGen use the same data: the OpenGL .spec files). Did you try including glLoadGen's headers before the Cocoa framework? You generally have to include glLoadGen's headers before any OS system-specific headers, even on Windows.

  4. Lorcán Mc Donagh reporter

    I'm definitely including glLoadGen's headers first in my code, before Cocoa.h, but it seems gltypes.h gets included multiples times in an order I have no control over (through Cocoa.Framework and precompiled headers also).

    Maybe I'm doing something stupid .. but GLEW's solution seems to have one problem: if code in Apple OpenGL / Cocoa expects a certain type we might run into problems if this is instead defined as another (although in this case an unsigned int should silently cast to a void*).

    I attached two patches:

    • glLoadGen_glspec_gltypes* with an alternative solution to issue #33
    • glLoadGen_gl_specloaderfunc to fix cast problems in gl_specloaderfunc.lua
  5. Jason McKesson repo owner

    Here's the thing. The glspec.lua files are generated directly from the .spec files on the OpenGL registry. These are the official repository for these definitions. And there, they say "typedef GLhandleARB unsigned int;".

    I simply don't feel comfortable making a change of this type for a platform that I can't personally test the results of the change on. I have instead opted to file a bug report with Khronos, who manages the .spec files. Granted, they haven't exactly been... prompt with dealing with .spec bugs in the past. But they are more likely to know exactly when it should be #defined as unsigned int and when as void*.

    Remember: this code used to work on MacOSX; GLEW used to work on MacOSX. So something changed in Apple's headers; it may be a problem with them.

    We'll see how they handle it.

    I'll accept the glSpecLoaderFunc patch however. Well, I would if it had been made against the main-line repo, rather than based on the modifications from the first one. Which means I now have to import it manually.

  6. Lorcán Mc Donagh reporter

    Ok, thanks a lot for going through all this trouble. Apple can be a pain sometimes ... they seem to like changing things in their APIs all the time, sometime even without notice. Adding variations to an open API like OpenGL makes even less sense - anybody else than Apple would get flamed for this.

    Sorry for the patch version mismatch, I'll be more careful in the future. Cheers

  7. Log in to comment