Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ArtOfWarfare

macrumors G3
Original poster
Nov 26, 2007
9,705
6,296
I'm slowly working my way through this book Introduction to OpenGL (perhaps too slowly... I think my understanding of C / Objective-C / Objective-C 2.0 / Cocoa / Cocoa Touch are all slipping away as I read this... hopefully looking over my previous projects will bring back the memories of how it all works...) and I noticed that one of the examples in it has:

Code:
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <stdlib.h>

I changed it to:

Code:
#import <Cocoa/Cocoa.h>
#import <OpenGL/gl.h>
#import <OpenGL/glu.h>
#import <GLUT/glut.h>

I ran it and it works fine... but it made me wonder about stdlib.h. Is it already included in cocoa.h? Or is it just that the example in the book didn't need stdlib.h to work properly and that in the future I may need to include it? (Where would I find the framework that includes it anyways?)
 
If you include the glut.h header file there is no need to include gl.h and glu.h as well. In fact it is specifically stated by the standards body not too as glut.h includes them itself in the correct order to satisfy certain platform issues.

In answer to your question cocoa.h does include it in a round about way.

Cocoa.h includes AppKit.h which in turn includes Foundation.h which includes CoreFoundation.h and then finally that includes stdlib.h. Of course you could have just looked in the header files yourself to see that :).
 
Cocoa.h includes AppKit.h which in turn includes Foundation.h which includes CoreFoundation.h and then finally that includes stdlib.h. Of course you could have just looked in the header files yourself to see that :).

I looked in the header files of Cocoa only... it didn't occur to me that it would be buried so many layers deep. But it confirms what I already suspected.

If you include the glut.h header file there is no need to include gl.h and glu.h as well. In fact it is specifically stated by the standards body not too as glut.h includes them itself in the correct order to satisfy certain platform issues.

Oh?

Odd that the examples in the book include all 3 then. Well, I changed it to only import glut.h now (and it still works.)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.