c++ - MacOS M1 -> fatal error : 'GLFW/glfw3.h' file not found

标签 c++ visual-studio-code glfw apple-m1

我有一个项目 (here)这适用于 Linux 和 intel MacOS,但在我的 Mac m1 上却不行。每当我尝试编译它时,我都会收到以下错误(操作:我正在使用 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

之前我运行了这三个命令并且它们成功运行,完全没有错误或警告,所以我认为一切正常。

brew install glfw
brew install sdl2
brew install sdl2_mixer

有人有什么想法吗?

最佳答案

我的问题已部分解决。有两个问题,GLFWSDL2

全局自由论坛

修复与此 thread 中提出的相同;简而言之,它包括:

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

这将告诉编译器在 opt/homebrew 中寻找东西,这是 homebrew for m1 安装包的地方,而不是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。我决定放弃尝试,只是从我的游戏中删除了声音(这是一项大学作业,删除功能没什么大不了的)。

关于c++ - MacOS M1 -> fatal error : 'GLFW/glfw3.h' file not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67373307/

相关文章:

c++ - 在模板方法中使用 typeid 时,如何摆脱 C4100 警告?

c++ - C++17 中包含 XPM 图像时发出警告

visual-studio-code - vscode prettier 设置问题

c++ - Cmake vs 命令行 : Error in Cmake, 不在命令行

opengl - glDrawPixels 不与 glfw 一起使用

c++ - 为什么 co_await 不能返回字符串?

c++ - 如果在生成 std​​::thread 后引发异常,则未捕获异常

Python VS 代码不连接 IPython 内核

visual-studio-code - 如何在Visual Studio Code(VSCode)中调试Cucumber?

c - 我的 OGL 程序找不到 gl.h 和 glu.h 了