MacOS M1 -> 致命错误:未找到“GLFW/glfw3.h”文件

8

我有一个项目(在这里),可以在Linux和英特尔macOS上运行,但是在我的Mac m1上不行。每当我尝试编译它时,就会出现以下错误(注意:我正在使用本机vscode m1):

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

在此之前,我运行了这三个命令,并且它们都成功地执行了,没有出现任何错误或警告,因此我认为一切都正常工作。

brew install glfw
brew install sdl2
brew install sdl2_mixer

有人有什么想法吗?


2
您需要确保库搜索路径正确。当您在M1 Mac上通过Homebrew安装时,默认情况下,它们将位于opt/homebrew目录中。 - Ranoiaetep
2个回答

10

我的问题被部分解决了。存在两个问题,GLFWSDL2

GLFW

解决方法与这个主题中提出的一样; 简而言之,解决方法包括:

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

这将告诉编译器在opt/homebrew寻找内容,这是m1homebrew安装软件包的位置,而不是usr/local

SDL2

我从以下网站下载了两个.dmg文件:

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

然后我去下载并复制了两个文件夹里的.framework目录,并粘贴到了/Library/Frameworks中。

这解决了之前的错误,系统找不到所需的头文件,但出现了一个新错误:symbols not found for architecture arm64。于是我决定停止尝试,并从我的游戏中去掉声音(这是一个大学作业,不必要的功能)。


2
在MacOS Monterey 12.6上,我通过安装xcode来解决了这个问题,然后使用homebrew安装了以下软件:
  1. glew
  2. glfw3
  3. xquartz
请注意保留HTML标签。
brew install glew glfw3
brew install --cask xquartz

然后我指向了X11文件夹和编译好的OpenGL示例程序。Github源代码来自:https://github.com/zamirmf/OpenGLOnMac

例如:

clang -o testopengl main.cpp \
  -L/opt/X11/lib -L/opt/homebrew/lib \
  -I/opt/X11/include -I/opt/homebrew/include  \
  -lglfw -framework OpenGL

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接