gpt4 book ai didi

c++ - 如何使用 cmake 在 mac 上链接 OpenGL 相关库?

转载 作者:行者123 更新时间:2023-11-30 05:03:09 26 4
gpt4 key购买 nike

我正在尝试使用 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。

关于c++ - 如何使用 cmake 在 mac 上链接 OpenGL 相关库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49559886/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com