4

I just tried to compile an open source C++ application on my Mac. I get the error GL/gl.h file not found. I know that this means that it can't find the open GL library, which it needs to compile and run. I am confused about what to do next because

  1. It seems like OS X includes built-in support for open gl. There is nothing to download.
  2. It seems like the header file names might be different for OpenGL on OSX and Linux ( OpenGL headers for OS X & Linux )

So I am confused about what to do next. Do I download OpenGL and link it to my project? Do I configure xcode to use a native version of OpenGL? Do I change the headers?

Can someone provide a little more direction. This answer gave windows/linux answers -- but not OS X: How to get the GL library/headers?

Community
  • 1
  • 1
bernie2436
  • 22,841
  • 49
  • 151
  • 244

2 Answers2

10

Apple thought it was clever if they were incompatible to everybody else and placed the OpenGL headers in a directory called OpenGL not just GL. So you must use

#include <OpenGL/gl.h>

on Apple systems and

#include <GL/gl.h>

everywhere else. Compiler predefined preprocessor macros are your friend here.

#ifdef __APPLE__
#  include <OpenGL/gl.h>
#else
#  include <GL/gl.h>
#endif/*__APPLE__*/
datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • You forgot to mention the silly `-framework OpenGL` compiler switch. After a while OS X does grow on you, up until you're forced to use Objective C :) – Andon M. Coleman Oct 01 '13 at 23:48
  • @AndonM.Coleman: Well, and that yes. I'll never get what's so terrific about those frameworks. What's wrong with libraries? MacOS X is one of the few systems I never fully got to wrap my head around it. Yes, I can program for it, I can use it. But I really can't contemplate many of its design choices. – datenwolf Oct 02 '13 at 00:17
  • 1
    Frameworks are just a convenient way of packaging up headers, libraries and related resources into a single bundle. It also supports having multiple versions of the libraries installed at once, and other handy features. It's cleaner than dumping all the `.h` files in `/usr/local/include` and all the `.dylib` files into `/usr/local/lib` where disparate packages are mixed up together. – gavinb Oct 02 '13 at 00:23
  • 1
    The nice thing about frameworks is that they package the headers, libraries, documentation, resources, etc. into a single location. Instead of spreading them out across /usr/local/share/man, /usr/local/include, /usr/local/lib, etc. you can download/package a framework as a single bundle and add it to your environment with no muss or fuss. But the added complexity of learning how this stuff all works since it is proprietary really undoes a lot of the convenience factor :-\ – Andon M. Coleman Oct 02 '13 at 00:24
1

"OS X includes built-in support for OpenGL" is right!

Windows also does! BUT the thing is that Windows only gives you access to OpenGL 1.1 functions... Everything above this must be done via extensions! OpenGL extensions can be found here: http://www.opengl.org/registry/

But because it's very boring to set up those extensions, you could use things like GLEW or similar...

Another very common issue is how to open the OpenGL context on Windows properly! If you follow old tutorials like NeHe you will have some problems nowadays. The solution is to use something like GLFW, glut, freeglut or similar...

With this pair "context + extensions" you will be able to easily create the context and use any function from the "modern OpenGL" functions that you are probably using on OS X. I particularly prefer "GLFW + GLEW"!

Wagner Patriota
  • 5,494
  • 26
  • 49