我已经在CLION中将我的简单C ++项目中的GLFW库链接起来了一段时间。我已经解决了现有问题及其解决方案,但在我的案例中似乎没有帮助。我的CMakeLists文件如下:
cmake_minimum_required(VERSION 3.6)
project(TestGame)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -v")
find_library(carbon_lib Carbon)
find_library(cocoa_lib Cocoa)
find_library(iokit_lib IOKit)
find_library(corevideo_lib CoreVideo)
find_library(opengl_lib OpenGL)
find_library(corefoundation_lib CoreFoundation)
set(frameworks
${carbon_lib}
${cocoa_lib}
${iokit_lib}
${corevideo_lib}
${opengl_lib}
${corefoundation_lib}
)
file(GLOB sources
"include/*.hpp"
"src/*.cpp"
"src/application/*.cpp"
"src/controlling/*.cpp"
"src/helper/*.cpp"
"src/render/*.cpp"
"src/texturing/*.cpp"
"src/translations/*.cpp"
"test/*.cpp"
)
find_package(GLEW REQUIRED)
find_package(GLFW3 REQUIRED)
find_package(SDL2 REQUIRED)
find_package(GLM REQUIRED)
find_package(SOIL REQUIRED)
include_directories(${GLEW_INCLUDE_DIRS} ${GLFW_INCLUDE_DIR} ${GLM_INCLUDE_DIR} ${SDL2_INCLUDE_DIR} ${SOIL_INCLUDE_DIRS} ${GLM_INCLUDE_DIRS})
add_executable(GameMain ${sources})
target_link_libraries(GameMain ${GLEW_LIBRARIES} ${GLFW_LIBRARIES} ${GLM_LIBRARIES} ${SDL2_LIBRARY} ${SOIL_LIBRARIES} ${frameworks})
我已经使用brew安装了GLFW3和GLFW2(显然v2是Cocoa需要的,我不知道为什么)(brew install glfw2或brew install glfw3 - with --build-bottle --static它没有由于内部cmake错误而工作,也尝试从最新源手动编译GLFW。
值得注意的是,我最近开始学习C ++ / CMake / CLion,所以我可能会忘记这里重要的事情 - 不要犹豫,要求更多信息,以便我可以添加这些信息。
值得注意的是,在Sierra OSX(目前正在运行最新的BETA)更新之前,我的应用程序运行良好,没有链接器错误。链接器错误如下:
Undefined symbols for architecture x86_64:
"_glfwCreateWindow", referenced from:
Application::Application(char const*, int, int) in Application.cpp.o
"_glfwMakeContextCurrent", referenced from:
Application::Application(char const*, int, int) in Application.cpp.o
"_glfwWindowHint", referenced from:
Application::Application(char const*, int, int) in Application.cpp.o
"_glfwWindowShouldClose", referenced from:
Application::run() in Application.cpp.o
这些与创建窗口的主条目文件有关。在包含目录时,CLion不会对任何被忽略的内容提出任何建议。我尝试了/没有列出所有这些框架,找到了一个解决方案,其中包含Cocoa / IOKit / CoreVideo / OpenGL以使GLFW3正常工作。尝试还包括Carbon / CoreFoundation,因为有些解决方案是关于这些的。
字面上没什么用。
答案 0 :(得分:1)
http://www.glfw.org/docs/latest/build_guide.html#build_link_cmake_package
您需要添加:
target_link_libraries(LearnGLSL ..any other libraries... glfw)