且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Cmake 链接库目标链接错误

更新时间:2021-06-30 04:02:57

target_link_libraries 的语法是:

target_link_libraries(your_executable_name libraries_list)

而且您不必添加add_definition 语句(target_link_libraries 添加此选项)

And you don't have to add add_definition statements (target_link_libraries adds this options)

OpenGL 和 GLEW 包也提供了一些有用的变量.

There are also some useful variables provided by OpenGL and GLEW packages.

你的 CMakeLists.txt 应该是这样的:

Your CMakeLists.txt should be like:

cmake_minimum_required (VERSION 2.6)
project (test)

find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)

include_directories(${OPENGL_INCLUDE_DIR} ${GLEW_INCLUDE_DIRS})

add_executable(test
    main.cpp
)

target_link_libraries(test ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES})

要记住的一个重要细节是将target_link_libraries 放在 add_executable(或add_library)之后线.

One important detail to keep in mind is to place the target_link_libraries after the add_executable (or add_library) line.