3

I am porting an open source C++ program for linux to os x. I have been changing lines from this

 #include <GL/gl.h> 

to this

#include <OpenGL/gl.h>

based on the advice from this post: How do I use Open GL in a C++ project that I am porting from Linux

That change gets rid of the compiler errors, but I am confused: where is xcode/the C++ compiler that it uses going to look for that file? If I search my xcode project, I don't see a directory called OpenGL or a file = gl.h?

I'm used to including images or javascript libraries in web pages based on the working directory of the .html file. Something else is happening in xcode here.

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

2 Answers2

4

On a Mac, you'll get those headers from the OpenGL framework. The headers are located at:

/System/Library/Frameworks/OpenGL.framework/Headers

Strictly speaking, that path is a symbolic link - the real location is:

/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers

Your toolchain will be able to find them if you pass -framework OpenGL on the compiler/linker command lines.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
1

If you've added the OpenGL framework to your project then Xcode will resolve OpenGL/ as "the headers folder for the current version within the OpenGL.framework". The files aren't copied into your project and you don't need to worry about where the frameworks are stored on disk or how they're laid out internally.

As of Xcode 5, if you have module support enabled you can just use @import OpenGL; both to include the symbols in that compiler unit and ensure the framework is included later by the linker.

Tommy
  • 99,986
  • 12
  • 185
  • 204
  • Really? Would not that generate a parse error in a C++ project? – Andon M. Coleman Oct 02 '13 at 22:56
  • @AndonM.Coleman it's immediately unclear to me, but I'd expect not — so that was an error on my part. Quick fix: compile as Objective-C++. E.g. change the file type in the right hand utilities view in Xcode, ø® change the file extensions to .mm. – Tommy Oct 02 '13 at 23:50