Having an issue with getting glfw to build on mac

on a m1 mac.

version 12.2 OS

trying to run this code.

i did

brew install glew and glfw.

I think my issue is I need to get my compiler to be aware of the files location. Any insights on how I can get it to wokr?

Here is my error:
main.cpp:2:10: fatal error: ‘GL/glew.h’ file not found
#include <GL/glew.h>
^~~~~~~~~~~
1 error generated.

Yes, you need to inform your compiler of the location of the GLEW files, in this case the location of the folder which contains the GL folder (since you specify #include <GL/glew.h>).

If you are building with the command line, then you must use the -I dir option, replacing dir with the directory.

If you are using XCode then you can specify the include directory using the UI - I’m afraid I don’t have XCode with me at the moment to check where that is but if you search the internet there is information on this.

Okay, I’m going to work on this and try it out.

I don’t use XCode, I’m trying to learn vi an C++, and I’m making this project to practice those.

Using grep I was able to find this.

in my opt/homebrew/Cellar/glew/2.2.0_1/include/GL

I have glew.h.

In /opt/homebrew/Cellar/glfw/3.4/include/GLFW

I have glfw3.h

g++ main.cpp -o main
-I/opt/homebrew/Cellar/glew/2.2.0_1/include
-I/opt/homebrew/Cellar/glfw/3.4/include
-L/opt/homebrew/Cellar/glew/2.2.0_1/lib
-L/opt/homebrew/Cellar/glfw/3.4/lib
-lglfw -lGLEW -framework OpenGL

Doing this let me compile it!

Posting my solution here if anyone else has a similar problem.

1 Like