OpenGL programming
By hkn at Wed, Nov 21 2007 12:58pm |
I'm trying to compile some C code (written for Linux) on OS X 10.4 and get into problems with opengl related includes. Specifically all statements of the sort
#include <GL/gl.h>
should read
#include <OpenGL/gl.h>
on the mac.
My question is: is there a way of accomplishing the same effect without acctually changing the code? I don't want to change a lot of files every time a new version of the code is released. On Linux the includes reside in /usr/includes so an easy fix here would be to add a symbolic link from GL to OpenGL, but on the Mac all the files are in a framework and I don't really know how to handle that.
Thanks
Håkan



Hi,
Hi,
Sorry you question took so long to get a reply, you have probably sorted it out now. I don't have an answer but just some suggestions
You could add a pre-processor #if statement that way the same file would compile on both platforms. But I don't know how to find out what OS if running.
There might be some tips in the example code folder that came with the developer tools, /Developer/Examples/GULT
Alternatively, yes the symbolic links might work, but we are getting a bit hack tastic at this point! You could do it like this
ln -s source file/folder destination file/folder
DAn
This work for me, in 10.4 or
This work for me, in 10.4 or 10.5
ifdef __APPLE__
#include OpenGL/gl.h
#else
#include gl.h
#endif
best,
s
p.s.:I couldn't post the <'s
using GL frameworks in the makefile
To get at the frameworks from a makefile, use the -framework argument to gcc. In all, I use these basic additions to my makefile when I build something against opengl. In principal, you should be able to adapt the syntax to use other frameworks as well:
LIBPATH += -L"/System/Library/Frameworks/OpenGL.framework/Libraries"
FRAMEWORKS = -framework GLUT
FRAMEWORKS += -framework OpenGL
GL_LIBS = -lGL -lGLU
# -- more makfile code follows....
Then add $(LIBPATH) $(FRAMEWORKS) $(GL_LIBS) into the compile part. Something like
main: main.o
$(CC) $(FRAMEWORKS) $(CFLAGS) -o $@ $(LIBPATH) $(GL_LIBS) $(OBJECTS)
Where CC is probably gcc, and CFLAGS might be something like -Wall -O. But this is an old post. You probably solved this months ago... I thought I'd post anyway, I had to dig for this info when I first was learning to use OpenGL, maybe it helps another person digging for the same thing at some time.
I have the answer
Hi,
I have just partecipated to a summer school on Scientific Visualization in 3D, and I learn how to use OpenGL.
I found the same problem like you, but I solved it. Ah, I have Leopard...and I use Xcode (and I suggest you to do so)
I use to program in C. So I've created my new project with Xcode (Command Line Utility / Standard Tool). I selected the main.c file and I added the OpenGL and the GLUT frameworks (in the project window: Action -> Add -> Existing Frameworks). Then in the main.c file I wrote:
#include < GLUT/glut.h >
#include < OpenGL/gl.h >
#include < OpenGL/glu.h >
(because I want to use OpenGL, GLU and GLUT library. Ah, sorry for the space after and before < and >, but otherwise they don't appear).
Hope this should resolve definitively this problem =)
Bye