In /usr/include ,
I tried grepping for GL gl and OpenGL .. .but can't find it.
Where are these header files located?
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
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
Headers
directory, so can we still use #include <OpenGL/gl.h>
to include them or do we need to do something else?
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.
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.