我正在尝试使用cmake在Mac上完成一个简单的GLFW教程,在那里我遇到一系列未定义的符号链接错误。我就此问题进行了研究,没有找到任何帮助。以下是我的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
答案 0 :(得分:1)
我找到了解决方案。显然GLFW3_LIBRARY没有定义,定义的变量应该是GLFW_LIBRARY。