如何在 CMake 中连接 QuaZip 库
How to connect the QuaZip library in CMake
我的项目使用了QuaZip库,需要通过CMake构建项目。如何将此库添加到 CMakeLists?
从图书馆我需要 JlCompress
我的 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}
)
构建错误:
CMake Warning at CMakeLists.txt:13 (find_package): By not providing
"Findquazip.cmake" in CMAKE_MODULE_PATH this project has asked CMake
to find a package configuration file provided by "quazip", but CMake
did not find one.
Could not find a package configuration file provided by "quazip"
with any of the following names:
quazipConfig.cmake
quazip-config.cmake
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.
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 的查找脚本名为 FindQuaZip5.cmake(在安装期间重命名)。所以对于 find quazip
你需要使用
find_package(QuaZip5)
查找脚本的含义在其头部描述:
# 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
一起使用,请添加以下行:
include_directories(${QUAZIP_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${QUAZIP_LIBRARIES})
我的项目使用了QuaZip库,需要通过CMake构建项目。如何将此库添加到 CMakeLists? 从图书馆我需要 JlCompress
我的 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}
)
构建错误:
CMake Warning at CMakeLists.txt:13 (find_package): By not providing "Findquazip.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "quazip", but CMake did not find one.
Could not find a package configuration file provided by "quazip" with any of the following names:
quazipConfig.cmake quazip-config.cmake
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.
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 的查找脚本名为 FindQuaZip5.cmake(在安装期间重命名)。所以对于 find quazip
你需要使用
find_package(QuaZip5)
查找脚本的含义在其头部描述:
# 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
一起使用,请添加以下行:
include_directories(${QUAZIP_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${QUAZIP_LIBRARIES})