问题描述
我的项目使用QuaZip库,我需要通过CMake构建该项目。如何将此库添加到CMakeLists?
从库中我需要JlCompress
My project uses the QuaZip library, and I need to build the project through CMake. How to add this library to CMakeLists? From the library I need JlCompress
我的CMakeList:
My CMakeLists:
cmake_minimum_required(VERSION 3.6)
#set_property(GLOBAL PROPERTY USE_FOLDERS ON)
#set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "cmake")
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
project(Archiver LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui)
find_package(zlib)
find_package(QuaZip5)
include_directories(${QUAZIP_INCLUDE_DIRS})
set(project_ui
mainwindow.ui)
set(project_headers
archive.h
mainwindow.h)
set(project_sources
main.cpp
archive.cpp
mainwindow.cpp)
qt5_wrap_ui(project_headers_wrapped ${project_ui})
qt5_wrap_cpp(project_sources_moc ${project_headers})
add_executable(${PROJECT_NAME} ${project_headers} ${project_sources}
${project_sources_moc} ${project_headers_wrapped})
target_link_libraries(${PROJECT_NAME}
PUBLIC
Qt5::Core
Qt5::Gui
Qt5::Widgets
${QUAZIP_LIBRARIES}
)
构建错误:
找不到软件包配置文件由 quazip
提供,并具有以下任何名称:
Could not find a package configuration file provided by "quazip" with any of the following names:
quazipConfig.cmake
quazip-config.cmake
将 quazip的安装前缀添加到CMAKE_PREFIX_PATH或设置
quazip_DIR到包含上述文件之一的目录。如果
quazip提供了单独的开发包或SDK,请确保已安装
。
Add the installation prefix of "quazip" to CMAKE_PREFIX_PATH or set "quazip_DIR" to a directory containing one of the above files. If "quazip" provides a separate development package or SDK, be sure it has been installed.
CMakeLists.txt上的CMake错误:txt:37 (target_link_libraries):target_link_libraries的
关键字签名已与
目标存档器一起使用。具有
目标的target_link_libraries的所有使用都必须是全关键字或全部使用。
CMake Error at CMakeLists.txt:37 (target_link_libraries): The keyword signature for target_link_libraries has already been used with the target "Archiver". 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:31(target_link_libraries)
推荐答案
quazip的查找脚本名为(在安装过程中重命名)。因此,要查找 quazip
,您需要使用
The find script for quazip is named FindQuaZip5.cmake (it is renamed during installation). So for find quazip
you need to use
find_package(QuaZip5)
查找脚本的含义在其头部进行了描述:
Meaning of the find script is described in its head:
# QUAZIP_FOUND - QuaZip library was found
# QUAZIP_INCLUDE_DIR - Path to QuaZip include dir
# QUAZIP_INCLUDE_DIRS - Path to QuaZip and zlib include dir (combined from QUAZIP_INCLUDE_DIR + ZLIB_INCLUDE_DIR)
# QUAZIP_LIBRARIES - List of QuaZip libraries
# QUAZIP_ZLIB_INCLUDE_DIR - The include dir of zlib headers
也就是说,要在代码中将 quazip
与 zlib
一起使用,请添加以下行:
That is, for use quazip
with zlib
in your code, add these lines:
include_directories(${QUAZIP_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${QUAZIP_LIBRARIES})
这篇关于如何在CMake中连接QuaZip库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!