【发布时间】:2021-09-19 20:59:46
【问题描述】:
你好,这个问题让我发疯了,我需要你的帮助。 我在 IOS High Sierra v10.13.6 上,我正在尝试在没有 XCode 的 mac 上的 VSC 上尝试 OpenGL。 所以我已经为正确的操作系统下载了库 GLFW。 我已经尝试了GLWF website 中的基本示例。
#include "../GLFW/glfw3.h"
// g++ -v main.cpp -o main.o -L/Library/Developer/CommandLineTools/usr/include -lglfw3 -framework OpenGL
// file was built for archive which is not the architecture being linked (x86_64):
int main(void)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
当我执行这个命令时:
g++ -v main.cpp -o main.o -L/Library/Developer/CommandLineTools/usr/include -lglfw3 -framework OpenGL
我在终端出现以下错误:
Undefined symbols for architecture x86_64:
"_glfwCreateWindow", referenced from:
_main in main-ca9141.o
"_glfwInit", referenced from:
_main in main-ca9141.o
"_glfwMakeContextCurrent", referenced from:
_main in main-ca9141.o
"_glfwPollEvents", referenced from:
_main in main-ca9141.o
"_glfwSwapBuffers", referenced from:
_main in main-ca9141.o
"_glfwTerminate", referenced from:
_main in main-ca9141.o
"_glfwWindowShouldClose", referenced from:
_main in main-ca9141.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我知道我来自这个警告:
ld: warning: ignoring file /Library/Developer/CommandLineTools/usr/include/libglfw3.a, file was built for archive which is not the architecture being linked (x86_64): /Library/Developer/CommandLineTools/usr/include/libglfw3.a
我用 lipo 命令检查了库,它说他的架构是 x86_64! 我不知道为什么它不起作用,你能帮帮我吗?
提前致谢。
【问题讨论】: