MacOS M1 -> fatal error: 'GLFW/glfw3.h' file not found
Asked Answered
S

2

10

I have a project (here) that works both on Linux and intel MacOS, but in my Mac m1 it doesn't. Whenever I try to compile it, I get the following errors (ops.: I'm using vscode m1 native):

pedrohaccorsi@MacBook-Air-de-Pedro dev % make
g++ -o app src/glad.c src/AudioManager.cpp src/Character.cpp src/SceneManager.cpp src/Source.cpp src/Sprite.cpp src/stb_image.cpp -g -Iinclude -F/Library/Frameworks -lglfw -ldl -framework SDL2 -I/Library/Frameworks/SDL2.framework/Headers -framework SDL2_mixer -I/Library/Frameworks/SDL2_mixer.framework/Headers


In file included from src/AudioManager.cpp:1:
include/AudioManager.h:1:10: fatal error: 'SDL2/SDL.h' file not found
#include <SDL2/SDL.h>
         ^~~~~~~~~~~~
1 error generated.
In file included from src/Character.cpp:1:
In file included from include/Character.h:1:
In file included from include/Sprite.h:6:
include/Shader.h:13:10: fatal error: 'GLFW/glfw3.h' file not found
#include <GLFW/glfw3.h>
         ^~~~~~~~~~~~~~
1 error generated.
In file included from src/SceneManager.cpp:1:
In file included from include/SceneManager.h:3:
include/Shader.h:13:10: fatal error: 'GLFW/glfw3.h' file not found
#include <GLFW/glfw3.h>
         ^~~~~~~~~~~~~~
1 error generated.
src/Source.cpp:10:17: warning: using directive refers to implicitly-defined namespace 'std'
using namespace std;
                ^
In file included from src/Source.cpp:12:
In file included from include/SceneManager.h:3:
include/Shader.h:13:10: fatal error: 'GLFW/glfw3.h' file not found
#include <GLFW/glfw3.h>
         ^~~~~~~~~~~~~~
1 warning and 1 error generated.
In file included from src/Sprite.cpp:1:
In file included from include/Sprite.h:6:
include/Shader.h:13:10: fatal error: 'GLFW/glfw3.h' file not found
#include <GLFW/glfw3.h>
         ^~~~~~~~~~~~~~
1 error generated.
make: *** [app] Error 1

Before hand I ran these three commands and they worked successfully, no errors nor warnings at all, so I assumed it was all working fine.

brew install glfw
brew install sdl2
brew install sdl2_mixer

Anyone has any ideas?

Selinski answered 3/5, 2021 at 17:35 Comment(1)
You want to make sure that your library search path was correct. When you install it through Homebrew on an M1 Mac, by default, they would be located in opt/homebrewChukker
S
12

My issue was partially solved. There were two problems, GLFWand SDL2.

GLFW

The fix was the same proposed in this thread; in a nutshell it consists in:

$ nano ~/.zshrc
> export CPATH=/opt/homebrew/include
> export LIBRARY_PATH=/opt/homebrew/lib

This will tell the compiler to look for things in opt/homebrew, which is where homebrew for m1 installs the packages, instead of usr/local.

SDL2

I downloaded the two .dmg files from the websites below

  1. https://www.libsdl.org/download-2.0.php
  2. https://www.libsdl.org/projects/SDL_mixer/

Then I went to the downloads and copied the .framework directory from both downloads and pasted into /Library/Frameworks.

This solved those errors from before, that the system could not find the includes, but a new error showed up: symbols not found for architecture arm64. I decided to quit trying and just removed the sound out of my game (it was a college assignment, no biggie in taking features out).

Selinski answered 4/5, 2021 at 3:10 Comment(1)
I had the error " 'GLFW/glfw3.h' file not found" too. And editing my ~/.zshrc file with export LIBRARY_PATH=/opt/homebrew/lib fixed it. Thanks!Embroider
A
2

On MacOS Monterey 12.6 I fixed the issue by installing xcode, then installed with homebrew:

  1. glew
  2. glfw3
  3. xquartz
brew install glew glfw3
brew install --cask xquartz

Then I pointed to the X11 folders and sample OpenGL program compiled. The github source code was taken from: https://github.com/zamirmf/OpenGLOnMac

For example:

clang -o testopengl main.cpp \
  -L/opt/X11/lib -L/opt/homebrew/lib \
  -I/opt/X11/include -I/opt/homebrew/include  \
  -lglfw -framework OpenGL
Allotrope answered 24/12, 2022 at 16:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.