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

cnwbcb6i  于 2022-12-27  发布在  Mac
关注(0)|答案(2)|浏览(415)

我有一个项目(here),在Linux和intel MacOS上都可以工作,但在我的Mac m1上却不行。每当我试图编译它时,我会得到以下错误(ops.:我使用的是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

有人有什么想法吗?

iih3973s

iih3973s1#

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

GLFW

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

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

这将告诉编译器在opt/homebrew中查找内容,homebrew for m1opt/homebrew中安装包,而不是usr/local

SDL2

我从下面的网站下载了两个.dmg文件

  1. https://www.libsdl.org/download-2.0.php
  2. https://www.libsdl.org/projects/SDL_mixer/
    然后我去下载,从两个下载中复制.framework目录并粘贴到/Library/Frameworks中。
    这解决了之前的错误,即系统无法找到包含,但出现了一个新的错误:X1 M9 N1 X.我决定放弃尝试,只是把声音从我的游戏中删除了(这是大学作业,去掉功能没什么大不了的)。
bf1o4zei

bf1o4zei2#

在MacOS Monterey 12.6上,我通过安装xcode修复了这个问题,然后安装了homebrew:
1.闪光

  1. glfw3基因
    1.石英
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

相关问题