12

Some context: I am going through a tutorial on using OpenGL. The tutorial requires a couple libraries in order to work. One of those libraries is FreeGLUT. I am on OS X using Lion.

I've downloaded FreeGLUT and followed the instructions for installation, but when I run the 'make all' command I get this error:

error: GL/gl.h: No such file or directory
error: GL/glu.h: No such file or directory

I've scoured the internet for a solution and all I've been able to understand from this is that the compiler is having trouble locating these files and that the path that the compiler is using needs to be changed.

EDIT: Okay, I've figured out that it's not the compiler, it is that for some reason those files are not there. Going to try figure out why they are not there.

genpfault
  • 51,148
  • 11
  • 85
  • 139
jasonaburton
  • 2,941
  • 7
  • 34
  • 48
  • I'm not familiar with Mac, but you need to install both the OpenGL and GLU development libraries to build FreeGLUT, which depends on them. – Bojangles Jun 02 '12 at 22:23
  • Using Xcode you can just add a library to a project and OpenGL is a library that can be added so I just assumed those files were installed. Any ideas on how I go about doing that? Hehe... – jasonaburton Jun 02 '12 at 22:28

3 Answers3

16

On Mac, the location of those header files are not the same as on Linux. So in the code, replace this:

#include <GL/gl.h>
#include <GL/glu.h>

with this:

#include <OpenGL/gl.h>
#include <OpenGL/glu.h>

and that should fix your issue.

  • Do you know where in the FreeGLUT files I will need to make that change? – jasonaburton Jun 02 '12 at 22:29
  • 1
    No, I don't, but as far as I know, you don't need it. GLUT is pre-installed on OS X, so you can just follow the tutorial with the GLUT you already have on your machine, and the code should be exactly the same. –  Jun 02 '12 at 22:30
  • 1
    The impression I got was that FreeGLUT was very different than GLUT and the example would not work as written. If I can't get this working, I will try using GLUT. – jasonaburton Jun 02 '12 at 22:36
  • So I found where I needed to make that change, but now I am getting a new error: "GL/glx.h: No such file or directory" (same thing) except this time when I changed it to OpenGL/glx.h the error still appeared... – jasonaburton Jun 02 '12 at 22:37
  • That is strange. I'm not very familiar with FreeGLUT, so I haven't had to mess with that before. I'm guessing the installation of GLUT on your machine is not compatible with the FreeGLUT you downloaded. Honestly, I'd just use regular old GLUT if I were you. –  Jun 02 '12 at 22:40
  • Well, then my next question is, what is the difference? Why am I being recommended to use FreeGLUT? (I'm just as unfamiliar as you, most likely more unfamiliar). – jasonaburton Jun 02 '12 at 22:42
  • It's my understanding that they do exactly the same thing. I just looked up the [Wikipedia article](http://en.wikipedia.org/wiki/Freeglut), and it looks like FreeGLUT is just an alternative to GLUT. –  Jun 02 '12 at 22:48
  • Okay. GLUT it is then. Thanks for your help! – jasonaburton Jun 02 '12 at 22:51
  • 1
    @jasonaburton: FreeGLUT is *not* the same thing as GLUT. FreeGLUT implements many of the same functions, but it also adds many more that were never in GLUT. I don't know what OSX ships with, but it's probably a hacked version of the original GLUT, which likely won't support any of the FreeGLUT extensions. – Nicol Bolas Jun 04 '12 at 01:09
  • cross-platform solution: `#ifndef __APPLE__ #include #else #include #endif` – Birchlabs Oct 15 '16 at 23:16
0

That tutorial, OpenGLBook.com, is based around OpenGL 4.0 core contexts, with 3.3 core contexts as an alternative. At best on OS X (with Mountain Lion) you'll get a 3.2 core context which is similar enough to 3.3 - but unfortunately this is incompatible with GLUT - OS X includes the original GLUT (unmodified due to licencing issues), which requires many obsolete OpenGL functions that aren't available in 3.2 core contexts.

If you want to do this tutorial on OS X (10.6.3 or later) without having to deal with many annoying incompatibilities, and with future-proof OpenGL, I recommend installing a recent version of XQuartz (2.7.2 or later), which includes FreeGLUT (2.8.0 to start with).

https://dl.bintray.com/xquartz/downloads/XQuartz-2.7.11.dmg

Community
  • 1
  • 1
RD1
  • 3,305
  • 19
  • 28
  • Hi, I was not able to get a 3.2 context using FreeGlut (via XQuartz). I was able to get a 2.1 context with out any issues, but I could only get 3.2 via Cocoa. I'd love to find out if this can be done. – Angus Forbes Aug 25 '12 at 21:52
0

install freeglut via macports, modify premake4.lua so that it builds the Unofficial OpenGL SDK in the glsdk apart from freeglut. manually copy and paste the lib and include folders of the freeglut (via macports) and modify #include_GL/freeglut.h> inside framework.cpp (framework folder) so that it finds the header. also fill the blanks in folder names, e.g. Tut 13 Impostors -> Tut_13_Impostors

it works for me

more details here

Community
  • 1
  • 1
Nikolaos Giotis
  • 281
  • 2
  • 23