【发布时间】:2014-08-12 06:44:26
【问题描述】:
我想从这个site(在底部)编译一个示例代码。我下载了 GLFW 3.0.4 源代码并将其构建在自定义位置。我使用了默认设置,并将 GLFW 构建为静态库。我的 CMakeLists.txt 看起来像这样:
cmake_minimum_required(VERSION 2.8)
project(glfw_test_project)
SET(CMAKE_CXX_FLAGS "-Wall -Werror -g -std=c++11")
find_package(OpenGL REQUIRED)
include_directories(/home/user/MyLibs/OpenGL/glfw-3.0.4/include)
link_directories(/home/user/MyLibs/OpenGL/glfw-3.0.4/build/src)
add_executable(glfw_test main.cpp)
target_link_libraries(glfw_test ${OPENGL_gl_LIBRARY})
target_link_libraries(glfw_test glfw3)
当我运行 make 时,我会得到以下信息:
Linking CXX executable glfw_test
/usr/bin/ld: /home/user/MyLibs/OpenGL/glfw-3.0.4/build/src/libglfw3.a(x11_clipboard.c.o): undefined reference to symbol 'XConvertSelection'
//usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [glfw_test] Error 1
make[1]: *** [CMakeFiles/glfw_test.dir/all] Error 2
make: *** [all] Error 2
怎么了?
编辑1 当我将 GLFW 构建为动态库时,一切正常。然后我的 CMakeLists.txt 中的最后一行必须替换为:
target_link_libraries(glfw_test glfw)
使用静态库有什么问题?
【问题讨论】:
-
我没有找到任何解决我的问题的方法。
-
在 CMake 术语中是什么意思?像这样:target_link_libraries(glfw_test X11 ${OPENGL_gl_LIBRARY}) ?
-
我对 CMake 不太熟悉,但我认为你说的是对的......当你尝试时会发生什么?
-
它不能解决问题。我得到了同样的信息。
标签: opengl ubuntu linker cmake glfw