问题
I am having difficulty compiling a C program using the OpenGL and GLUT frameworks on Mac OSX. I am just getting started and I attempted to run code from this tutorial, on how to install OpenGL. http://www.prinmath.com/csci5229/misc/install.html.
Here is the code:
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
int main(){
return 0;
}
I am trying to compile it with:
gcc -o foo foo.c -framework GLUT -framework OpenGL
I am receiving this error:
foo.c:2:23: error: GLUT/glut.h: No such file or directory
After doing some further research here, http://web.eecs.umich.edu/~sugih/courses/eecs487/glut-howto/, I looked in /System/Library/Frameworks/ and both OpenGL.framework, and GLUT.framework where present.
Any help is greatly appreciated! Thank you!
回答1:
You need to install OpenGL Utility Toolkit glutg3-dev lib.If it is already there then compile with -lglut -lGLU -lGL option.
回答2:
Without installing glutg3-dev you can use OS X GLUT and OpenGL frameworks as follows
gcc -o foo foo.c -L/System/Library/Frameworks -framework GLUT -framework OpenGL
notice that it is important to tell the compiler the path to the frameworks
来源:https://stackoverflow.com/questions/18372651/compiling-opengl-and-glut-osx