如何修复当前的 openGL 错误,我的 cmakelist 可能是我的问题
How do I fix my current openGL error, my cmakelist may be my issue
我已经包含了库 并且我的所有语法都是正确的,但是我收到了这个错误。
Undefined symbols for architecture arm64:
"_glBegin", referenced from:
triangle(float*, float*, float*) in main.cpp.o
"_glClear", referenced from:
displayTriangle() in main.cpp.o
"_glClearColor", referenced from:
_main in main.cpp.o
"_glColor3f", referenced from:
drawTetrahedron(int) in main.cpp.o
"_glEnable", referenced from:
_main in main.cpp.o
"_glEnd", referenced from:
triangle(float*, float*, float*) in main.cpp.o
"_glFlush", referenced from:
displayTriangle() in main.cpp.o
"_glLoadIdentity", referenced from:
displayTriangle() in main.cpp.o
"_glMatrixMode", referenced from:
reshapeWindow(int, int) in main.cpp.o
"_glOrtho", referenced from:
reshapeWindow(int, int) in main.cpp.o
"_glVertex3fv", referenced from:
triangle(float*, float*, float*) in main.cpp.o
"_glViewport", referenced from:
reshapeWindow(int, int) in main.cpp.o
"_glutCreateWindow", referenced from:
_main in main.cpp.o
"_glutDisplayFunc", referenced from:
_main in main.cpp.o
"_glutInit", referenced from:
_main in main.cpp.o
"_glutInitDisplayMode", referenced from:
_main in main.cpp.o
"_glutInitWindowSize", referenced from:
_main in main.cpp.o
"_glutMainLoop", referenced from:
_main in main.cpp.o
"_glutPostRedisplay", referenced from:
reshapeWindow(int, int) in main.cpp.o
"_glutReshapeFunc", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
我觉得我的 cmakefile 是我的问题,但我不知道从哪里开始。
请提供更多详细信息,例如 CMakeLists.txt 的相关部分,以获取更多信息并更快地从社区获得帮助。
现在,查看错误日志,您似乎 cross-compiling 使用 arm-based 编译器的源文件。
错误消息“ld: symbol(s) not found for architecture arm64”在我看来是一个链接器问题,你应该在 find_package() 中进行链接调用 CMakeLists.txt对于 OpenGL。
因此,首先,您应该首先执行两个步骤,看看它是否能解决您的问题:
1.确保 CMake 构建系统指向正确的编译器工具链路径(此处为 arm 编译器)。
同样参考CMake官网:
https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html
2。确保您链接的是 OpenGL
find_package(需要 OpenGL)
target_include_directories(your_executable_name PUBLIC ${OPENGL_INCLUDE_DIR})
target_link_libraries(your_executable_name PUBLIC ${OPENGL_LIBRARIES})
我已经包含了库
Undefined symbols for architecture arm64:
"_glBegin", referenced from:
triangle(float*, float*, float*) in main.cpp.o
"_glClear", referenced from:
displayTriangle() in main.cpp.o
"_glClearColor", referenced from:
_main in main.cpp.o
"_glColor3f", referenced from:
drawTetrahedron(int) in main.cpp.o
"_glEnable", referenced from:
_main in main.cpp.o
"_glEnd", referenced from:
triangle(float*, float*, float*) in main.cpp.o
"_glFlush", referenced from:
displayTriangle() in main.cpp.o
"_glLoadIdentity", referenced from:
displayTriangle() in main.cpp.o
"_glMatrixMode", referenced from:
reshapeWindow(int, int) in main.cpp.o
"_glOrtho", referenced from:
reshapeWindow(int, int) in main.cpp.o
"_glVertex3fv", referenced from:
triangle(float*, float*, float*) in main.cpp.o
"_glViewport", referenced from:
reshapeWindow(int, int) in main.cpp.o
"_glutCreateWindow", referenced from:
_main in main.cpp.o
"_glutDisplayFunc", referenced from:
_main in main.cpp.o
"_glutInit", referenced from:
_main in main.cpp.o
"_glutInitDisplayMode", referenced from:
_main in main.cpp.o
"_glutInitWindowSize", referenced from:
_main in main.cpp.o
"_glutMainLoop", referenced from:
_main in main.cpp.o
"_glutPostRedisplay", referenced from:
reshapeWindow(int, int) in main.cpp.o
"_glutReshapeFunc", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
我觉得我的 cmakefile 是我的问题,但我不知道从哪里开始。
请提供更多详细信息,例如 CMakeLists.txt 的相关部分,以获取更多信息并更快地从社区获得帮助。
现在,查看错误日志,您似乎 cross-compiling 使用 arm-based 编译器的源文件。
错误消息“ld: symbol(s) not found for architecture arm64”在我看来是一个链接器问题,你应该在 find_package() 中进行链接调用 CMakeLists.txt对于 OpenGL。
因此,首先,您应该首先执行两个步骤,看看它是否能解决您的问题:
1.确保 CMake 构建系统指向正确的编译器工具链路径(此处为 arm 编译器)。
同样参考CMake官网: https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html
2。确保您链接的是 OpenGL
find_package(需要 OpenGL)
target_include_directories(your_executable_name PUBLIC ${OPENGL_INCLUDE_DIR})
target_link_libraries(your_executable_name PUBLIC ${OPENGL_LIBRARIES})