如何使用CMAKE在Mac上链接与OpenGL相关的库
How to link OpenGL related libraries on mac using cmake?
我正在尝试使用cmake在Mac上完成一个简单的GLFW教程,在那里我遇到了一系列 undefined Symbol 链接错误。我对这个问题进行了研究,没有找到帮助。以下是我的cmakelists.txt。
cmake_minimum_required(VERSION 3.3)
project(GL_Template)
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})
find_package(GLM REQUIRED)
find_package(GLEW REQUIRED STATIC)
include_directories(${GLM_INCLUDE_DIR})
include_directories(/usr/local/include)
include_directories(./include)
find_library(COCOA_LIBRARY Cocoa REQUIRED)
find_library(IOKIT_LIBRARY IOKit REQUIRED)
find_library(COREVID_LIBRARY CoreVideo REQUIRED)
message(${COCOA_LIBRARY})
message(${IOKIT_LIBRARY})
message(${COREVID_LIBRARY})
file(GLOB A_SOURCE ./src/*.cpp)
add_executable(Hello example/main.cpp ${A_SOURCE})
target_link_libraries(Hello ${GLEW_LIBRARY} ${GLFW3_LIBRARIES})
target_link_libraries(Hello ${COCOA_LIBRARY} ${COREVID_LIBRARY} ${IOKIT_LIBRARY})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Cocoa -framework OpenGL -framework IOKit")
任何帮助都会有所帮助。以下是错误消息
Undefined symbols for architecture x86_64:
"_glfwCreateWindow", referenced from:
_main in main.cpp.o
"_glfwGetTime", referenced from:
_main in main.cpp.o
"_glfwInit", referenced from:
_main in main.cpp.o
"_glfwMakeContextCurrent", referenced from:
_main in main.cpp.o
"_glfwPollEvents", referenced from:
_main in main.cpp.o
"_glfwSetCursorPosCallback", referenced from:
_main in main.cpp.o
"_glfwSetInputMode", referenced from:
_main in main.cpp.o
"_glfwSetKeyCallback", referenced from:
_main in main.cpp.o
"_glfwSetScrollCallback", referenced from:
_main in main.cpp.o
"_glfwSetWindowShouldClose", referenced from:
key_callback(GLFWwindow*, int, int, int, int) in main.cpp.o
"_glfwSwapBuffers", referenced from:
_main in main.cpp.o
"_glfwTerminate", referenced from:
_main in main.cpp.o
"_glfwWindowHint", referenced from:
_main in main.cpp.o
"_glfwWindowShouldClose", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [Hello] Error 1
make[1]: *** [CMakeFiles/Hello.dir/all] Error 2
make: *** [all] Error 2
我找到了解决方案。显然,glfw3_library尚未定义,并且定义的变量应为glfw_library。
相关文章:
- 如何在 debian 下正确链接一个 opengl 程序?
- 在 CLion (MacOS) 中使用 OpenGL 和 GLUT 库时出现链接错误
- OpenGL 程序无法链接?
- 使用 CMake 在 Mac 上链接静态 GLFW 和 OpenGL
- 链接 openGL 库失败,因为它无法打开 libgl.so ...但它就在那里
- OpenGL 程序着色器链接错误
- 如何使用CMAKE在Mac上链接与OpenGL相关的库
- OpenGL 着色器链接错误,没有错误消息
- 无法在生成文件中链接 opengl 库
- OpenGL GLut 与 Windows 8 64 位上的 Visual Studio 2013 链接问题
- OpenGL SDL链接错误
- Ubuntu 13.10 C++ OpenGL GLUT - 链接问题 - 未定义对"glClearColor"的引用
- MinGW-w64 OpenGL 链接器错误
- 非官方OpenGL SDK链接问题-未定义引用
- OpenGL GLX_EXT_swap_control存在,但无法链接函数
- OpenGL - 链接两个纹理不起作用
- OpenGL链接问题
- OpenGL链接器错误,使用未编译的着色器进行链接
- QT OpenGL链接错误
- OpenGL 链接错误?未解析的外部 glCreateShader()