Mac OS with M1 在使用 glfw glew 时遇到错误
Mac OS with M1 encounters with an error when using glfw glew
error!
ld: warning: ignoring file /opt/homebrew/Cellar/glfw/3.3.2/lib/libglfw.3.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
"_glfwCreateWindow", referenced from:
GLWindow::GLWindow(int, int, char*) in MagicCubeLauncher.cpp.o
"_glfwDestroyWindow", referenced from:
GLWindow::~GLWindow() in MagicCubeLauncher.cpp.o
"_glfwGetKey", referenced from:
Render::processInput() in MagicCubeLauncher.cpp.o
"_glfwGetProcAddress", referenced from:
GLWindow::GLWindow(int, int, char*) in MagicCubeLauncher.cpp.o
"_glfwGetTime", referenced from:
Render::initRenderLayer() in MagicCubeLauncher.cpp.o
getTime() in MagicCubeLauncher.cpp.o
"_glfwInit", referenced from:
Shader::Shader(char const*, char const*) in MagicCubeLauncher.cpp.o
GLWindow::GLWindow(int, int, char*) in MagicCubeLauncher.cpp.o
"_glfwMakeContextCurrent", referenced from:
GLWindow::GLWindow(int, int, char*) in MagicCubeLauncher.cpp.o
"_glfwPollEvents", referenced from:
Render::initRenderLayer() in MagicCubeLauncher.cpp.o
"_glfwSetCursorPosCallback", referenced from:
Render::init() in MagicCubeLauncher.cpp.o
"_glfwSetFramebufferSizeCallback", referenced from:
Render::init() in MagicCubeLauncher.cpp.o
"_glfwSetInputMode", referenced from:
Render::processInput() in MagicCubeLauncher.cpp.o
"_glfwSetScrollCallback", referenced from:
Render::init() in MagicCubeLauncher.cpp.o
"_glfwSetWindowShouldClose", referenced from:
Render::processInput() in MagicCubeLauncher.cpp.o
"_glfwSwapBuffers", referenced from:
Render::initRenderLayer() in MagicCubeLauncher.cpp.o
"_glfwTerminate", referenced from:
GLWindow::GLWindow(int, int, char*) in MagicCubeLauncher.cpp.o
Render::clear() in MagicCubeLauncher.cpp.o
"_glfwWindowHint", referenced from:
GLWindow::GLWindow(int, int, char*) in MagicCubeLauncher.cpp.o
"_glfwWindowShouldClose", referenced from:
Render::initRenderLayer() in MagicCubeLauncher.cpp.o
ld: symbol(s) not found for architecture x86_64
可以直接用Rosetta 2编译成arm64框架使用吗?
如果没有,我可以使用其他方法在这个框架上 运行 它吗
或者我需要等待 glew 和 glfw 支持它?
我 运行 之前解决过这个问题,我终于找到了解决方法。这里发生的事情是您的编译器正在为错误的体系结构构建。您需要指定要为 Apple Silicon 进行编译才能使其正常工作。由于您没有指定您的构建系统,我将使用我使用的系统,在本例中是 CMake。
您只需添加 CMAKE_APPLE_SILICON_PROCESSOR 选项,如下所示:
# Inside of your `build` directory
$ cmake -DCMAKE_APPLE_SILICON_PROCESSOR=arm64 ..
如果没有这个,我的代码会明确指定 x86_64
架构并抛出您发布的错误。这可能不是灵丹妙药,但这是我解决上述问题的方法。您需要为您的系统执行与此等效的任何操作,或者如果您手动编译,则明确指定体系结构。
error!
ld: warning: ignoring file /opt/homebrew/Cellar/glfw/3.3.2/lib/libglfw.3.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
"_glfwCreateWindow", referenced from:
GLWindow::GLWindow(int, int, char*) in MagicCubeLauncher.cpp.o
"_glfwDestroyWindow", referenced from:
GLWindow::~GLWindow() in MagicCubeLauncher.cpp.o
"_glfwGetKey", referenced from:
Render::processInput() in MagicCubeLauncher.cpp.o
"_glfwGetProcAddress", referenced from:
GLWindow::GLWindow(int, int, char*) in MagicCubeLauncher.cpp.o
"_glfwGetTime", referenced from:
Render::initRenderLayer() in MagicCubeLauncher.cpp.o
getTime() in MagicCubeLauncher.cpp.o
"_glfwInit", referenced from:
Shader::Shader(char const*, char const*) in MagicCubeLauncher.cpp.o
GLWindow::GLWindow(int, int, char*) in MagicCubeLauncher.cpp.o
"_glfwMakeContextCurrent", referenced from:
GLWindow::GLWindow(int, int, char*) in MagicCubeLauncher.cpp.o
"_glfwPollEvents", referenced from:
Render::initRenderLayer() in MagicCubeLauncher.cpp.o
"_glfwSetCursorPosCallback", referenced from:
Render::init() in MagicCubeLauncher.cpp.o
"_glfwSetFramebufferSizeCallback", referenced from:
Render::init() in MagicCubeLauncher.cpp.o
"_glfwSetInputMode", referenced from:
Render::processInput() in MagicCubeLauncher.cpp.o
"_glfwSetScrollCallback", referenced from:
Render::init() in MagicCubeLauncher.cpp.o
"_glfwSetWindowShouldClose", referenced from:
Render::processInput() in MagicCubeLauncher.cpp.o
"_glfwSwapBuffers", referenced from:
Render::initRenderLayer() in MagicCubeLauncher.cpp.o
"_glfwTerminate", referenced from:
GLWindow::GLWindow(int, int, char*) in MagicCubeLauncher.cpp.o
Render::clear() in MagicCubeLauncher.cpp.o
"_glfwWindowHint", referenced from:
GLWindow::GLWindow(int, int, char*) in MagicCubeLauncher.cpp.o
"_glfwWindowShouldClose", referenced from:
Render::initRenderLayer() in MagicCubeLauncher.cpp.o
ld: symbol(s) not found for architecture x86_64
可以直接用Rosetta 2编译成arm64框架使用吗?
如果没有,我可以使用其他方法在这个框架上 运行 它吗 或者我需要等待 glew 和 glfw 支持它?
我 运行 之前解决过这个问题,我终于找到了解决方法。这里发生的事情是您的编译器正在为错误的体系结构构建。您需要指定要为 Apple Silicon 进行编译才能使其正常工作。由于您没有指定您的构建系统,我将使用我使用的系统,在本例中是 CMake。
您只需添加 CMAKE_APPLE_SILICON_PROCESSOR 选项,如下所示:
# Inside of your `build` directory
$ cmake -DCMAKE_APPLE_SILICON_PROCESSOR=arm64 ..
如果没有这个,我的代码会明确指定 x86_64
架构并抛出您发布的错误。这可能不是灵丹妙药,但这是我解决上述问题的方法。您需要为您的系统执行与此等效的任何操作,或者如果您手动编译,则明确指定体系结构。