[英]How to link opengl library on CMake using keyword signature
I am previously using Visual Studio with NuGet for all package. 我以前将Visual Studio与NuGet一起用于所有软件包。 Now I change to CMake.
现在我换成CMake。
Now I am using vcpkg to manage library. 现在我正在使用vcpkg来管理库。
However, I need OpenGl 但是,我需要OpenGl
The command of Cmake to link freeglut, glew, glm, libpng, zlib was provide by vcpkg. Cmake链接freeglut,glew,glm,libpng,zlib的命令由vcpkg提供。 But not OpenGL.
但不是OpenGL。
cmake_minimum_required(VERSION 3.0)
project(little_plane)
set(CMAKE_CXX_STANDARD 14)
add_executable(little_plane main.cpp)
# ./vcpkg install freeglut
find_package(GLUT REQUIRED)
target_link_libraries(little_plane PRIVATE GLUT::GLUT)
## ./vcpkg install glew
#find_package(GLEW REQUIRED)
#target_link_libraries(little_plane PRIVATE GLEW::GLEW)
#
# glm
find_package(glm CONFIG REQUIRED)
target_link_libraries(little_plane PRIVATE glm)
# ./vcpkg install libpng
find_package(PNG REQUIRED)
target_link_libraries(little_plane PRIVATE PNG::PNG)
##
find_package(ZLIB REQUIRED)
target_link_libraries(little_plane PRIVATE ZLIB::ZLIB)
find_package(OpenGL REQUIRED)
if (OPENGL_FOUND)
message("opengl found")
message("include dir: ${OPENGL_INCLUDE_DIR}")
message("link libraries: ${OPENGL_gl_LIBRARY}")
else (OPENGL_FOUND)
message("opengl not found")
endif()
target_link_libraries(little_plane ${OPENGL_gl_LIBRARY})
find_package(glfw3 CONFIG REQUIRED)
target_link_libraries(little_plane PRIVATE glfw)
With the CMakeLists.txt above, I run cmake .
使用上面的CMakeLists.txt,我运行
cmake .
opengl found
include dir: /usr/include
link libraries: /usr/lib/x86_64-linux-gnu/libGL.so
CMake Error at CMakeLists.txt:40 (target_link_libraries):
The keyword signature for target_link_libraries has already been used with
the target "little_plane". All uses of target_link_libraries with a target
must be either all-keyword or all-plain.
The uses of the keyword signature are here:
* CMakeLists.txt:10 (target_link_libraries)
* CMakeLists.txt:20 (target_link_libraries)
* CMakeLists.txt:24 (target_link_libraries)
* CMakeLists.txt:28 (target_link_libraries)
CMake Error at CMakeLists.txt:44 (target_link_libraries):
The plain signature for target_link_libraries has already been used with
the target "little_plane". All uses of target_link_libraries with a target
must be either all-keyword or all-plain.
The uses of the plain signature are here:
* CMakeLists.txt:40 (target_link_libraries)
-- Configuring incomplete, errors occurred!
Which mean opengl is installed on my system. 这意味着opengl已安装在我的系统上。 I just don't know how to use target_link_libraries to link with my project.
我只是不知道如何使用target_link_libraries链接到我的项目。
Provide answer that can copy and paste into CMakeLists.txt if possible. 提供可以复制并粘贴到CMakeLists.txt中的答案(如果可能)。
All your previous target_link_libraries
contain a transitivity keyword ( PRIVATE
in all cases), but you have not provided any when linking OpenGL. 您先前的所有
target_link_libraries
都包含一个传递性关键字(在所有情况下均为PRIVATE
),但在链接OpenGL时未提供任何关键字。 So just add that too: 因此,也只需添加:
target_link_libraries(little_plane PRIVATE ${OPENGL_gl_LIBRARY})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.