【问题标题】:MacOS M1 -> fatal error: 'GLFW/glfw3.h' file not foundMacOS M1 -> 致命错误:找不到“GLFW/glfw3.h”文件
【发布时间】:2021-05-03 17:35:17
【问题描述】:

我有一个项目(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

有人有什么想法吗?

【问题讨论】:

  • 您要确保您的库搜索路径正确。当您在 M1 Mac 上通过 Homebrew 安装它时,默认情况下,它们将位于 opt/homebrew

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


【解决方案1】:

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

GLFW

修复与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。我决定放弃尝试,只是从我的游戏中删除了声音(这是一项大学作业,删除功能没什么大不了的)。

【讨论】:

    猜你喜欢
    • 2022-01-18
    • 2018-09-10
    • 2022-12-15
    • 1970-01-01
    • 1970-01-01
    • 2021-06-14
    • 1970-01-01
    • 1970-01-01
    • 2021-07-04
    相关资源
    最近更新 更多