29
votes

In /usr/include ,

I tried grepping for GL gl and OpenGL .. .but can't find it.

Where are these header files located?

5

5 Answers

31
votes

They are located at /System/Library/Frameworks/OpenGL.framework/Headers. To include them, just use:

   #include <OpenGL/gl.h>
   #include <OpenGL/glu.h>
   #include <OpenGL/glext.h>
   #include <GLUT/glut.h>

etc. Make sure to link against the appropriate frameworks, eg)

cc <your_file.c> -framework GLUT -framework OpenGL 

for OpenGL and GLUT

24
votes

This is a good old thread to revive, because the correct answer changed. The accepted answer of /System/Library/Frameworks/OpenGL.framework/Headers was totally correct when it was written. But with Xcode 5 (I believe it changed with Xcode 4 already), this is not the case anymore.

All SDK files are now installed into /Applications/Xcode.app. The exact location of the headers depends on the platform the application is built against. As an example, the OpenGL headers for OS X 10.9 are in:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/OpenGL.framework/Headers

3
votes

It's worth noting that one also needs to have XCode itself set up (not just installed), as well as the XCode Command-Line Tools, even if one is not building the application in XCode.

1
votes

XCode automatically exposes all header files from a framework added to a project via the framework's name. So, "cocoa.h" is part of "cocoa.framework" - hence #include <cocoa/cocoa.h>

OpenGl is included <OpenGL/gl.h> rather than the more expected <GL/gl.h> on other platforms.

1
votes

In MacOS 10.12.6, they're under /opt/X11/include, e.g. /opt/X11/include/GL/gl.h.