1
votes

I am using a mac, but i am not programming in XCode

A few months ago i was trying to learn to use OpenGL in C++, and it did work quite well. I was using the GLFW, GLEW and GLM libraries, and i was able to write .cpp files, that i could compile and run without problems, and which did work exactly as intended.
I was writing my .cpp files in a text editor which is not XCode, and i was compiling from the terminal using this line:

g++ input.cpp -o output -lglfw3 -lglew -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo

I included the GLEW library using this line:

#include <GL/glew.h>  

and it did work perfectly

Then i spend a few month on some other projects, which did not use openGL, and now i am planning to do something that does require openGL, and i am still not using XCode and i am still compiling using the terminal the exact same way, but now i get this error, when compiling on the terminal using the line i mentioned before:

 fatal error: 'GL/GLEW.h' file not found

This even happens, when i try compilling old projects, which worked perfectly, without causing error when including GLEW, month ago, even though i didn't change anything.

To be perfectly clear

#include <GL/glew.h>  

Did yes a few month ago include GLEW without causing any errors, but now it doesn't work, and now it does cause this error:

 fatal error: 'GL/GLEW.h' file not found

My question is then; Why can't i include GLEW like i used to, and how am i supposed to include GLEW now? Does this have anything to do with the latest updates of the system (el capitan)? Will i have to use a library which is not GLEW ? Or will i to be able to use openGL in C++ have to stop using mac or start start using XCode?

note: I am 100% sure: that i have GLEW installed; that i was able to include GLEW before; and that it was possible to compile .cpp files on mac from terminal even, though openGL was used, and the file where not written in XCode.

1
Did you set the include path to where GLEW is installed? If not, your compiler can't find the headers. - Shadowwolf
The entire problem is that the compiler claims that it can't find the header, but i do not know what to write instead of GL/glew, so that the compiler can find the header - Nikolaj
No the GL/glew.h is correct, on the command line you can specify an include path using the -I option. This is a directory where the compiler will search for header files. Say for example you stored your header files in "/home/headers", then you'll need to specify -I/home/headers when invoking the compiler. - Shadowwolf
I am not sure how to find the include path, i only know that it once was good enough to write -lglew - Nikolaj
Or rather, i can get Homebrew, the tool i used to installed GLEW, to say that GLEW is in /usr/local/Cellar/glew/1.12.0, but that does not work - Nikolaj

1 Answers

-1
votes

<GL/glew.h> is not a standard header file on Mac OS. Meaning, it's not part of the system or Xcode installation. If you previously had it on your system, it was part of something you installed in addition to the standard development tools.

Chances are that whatever package you previously installed to get <GL/glew.h> is not on your current system. You will have to install it explicitly, and make sure that the location you install it to is part of your include path.

That said, GLEW is absolutely unnecessary on Mac OS. It is used for extension loading on systems that do not have headers/libraries for current OpenGL versions (like Windows and Linux). On Mac OS, there are headers and libraries that contain all the entry points for the OpenGL version supported by the system. An extension loader servers no useful purpose.

So the easiest solution is to simply remove/disable all GLEW dependencies when you're building on Mac OS.