31

In /usr/include ,

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

Where are these header files located?

anon
  • 41,035
  • 53
  • 197
  • 293

5 Answers5

33

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

  • 8
    There's no need to include glut.h unless you are using GLUT. When you are using GLUT there's no need to include gl.h or glu.h, since glut.h includes gl.h and glu.h, but you have to add both the GLUT and OpenGL frameworks to an Xcode project. – Mr. Berna Feb 04 '10 at 14:58
26

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

Reto Koradi
  • 53,228
  • 8
  • 93
  • 133
  • Really? I don't think so. I'm on Sierra and my header files are still in /System/Library/Frameworks/OpenGL.framework/Headers/ – frankliuao May 05 '18 at 19:03
  • While this comment is still relevant (5 years later on Mojave), I am confused as to how the headers get linked in. Currently the headers are just dumped in the `Headers` directory, so can we still use `#include ` to include them or do we need to do something else? – iHowell Jul 20 '19 at 18:58
  • This comment really saved me. I've been using Monterey and the frameworks were not in their usual folder anymore (which was inside System). Using this path (which is inside Applications/Xcode.app/ ...) worked for me. – Yvens Rebouças Serpa Oct 27 '22 at 21:27
3

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.

Walter Nissen
  • 16,451
  • 4
  • 26
  • 27
  • 1
    Can you clarify what you mean by having XCode set up? How would one go about doing that, or know if it had been done? – LarsH Jun 06 '18 at 00:26
  • 2
    Installing XCode from the App Store is the first step, then you need to run it, and it will do some further setup. If the directories above are there, then it has been done. – Walter Nissen Feb 01 '19 at 22:25
1

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.

Chris Becke
  • 34,244
  • 12
  • 79
  • 148
1

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

LarsH
  • 27,481
  • 8
  • 94
  • 152