Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cmake 如何在Ubuntu上的Clion中添加Ziplib库_Cmake_Linker Errors - Fatal编程技术网

Cmake 如何在Ubuntu上的Clion中添加Ziplib库

Cmake 如何在Ubuntu上的Clion中添加Ziplib库,cmake,linker-errors,Cmake,Linker Errors,我正试图使用ubuntu上的Clion将ZipLip添加到我的项目中,但我有一个输出: ====================[ Build | TryZip | Debug ]================================== /home/david/Snap/clion-2019.2.4/bin/cmake/linux/bin/cmake --build /home/david/CLionProjects/TryZip/cmake-build-debug --t

我正试图使用ubuntu上的Clion将ZipLip添加到我的项目中,但我有一个输出:

====================[ Build | TryZip | Debug ]==================================

/home/david/Snap/clion-2019.2.4/bin/cmake/linux/bin/cmake --build 
   /home/david/CLionProjects/TryZip/cmake-build-debug --target TryZip -- -j 2
[ 13%] Built target bzip2
[ 31%] Built target zlib
[ 83%] Built target lzma
[ 95%] Built target ZipLib
Scanning dependencies of target TryZip
[ 97%] Linking CXX executable ../bin/TryZip
/usr/bin/ld: cannot find -lExternalLibrary/ZipLib
collect2: error: ld returned 1 exit status
CMakeFiles/TryZip.dir/build.make:102: recipe for target '../bin/TryZip' failed
make[3]: *** [../bin/TryZip] Error 1
CMakeFiles/Makefile2:109: recipe for target 'CMakeFiles/TryZip.dir/all' failed
make[2]: *** [CMakeFiles/TryZip.dir/all] Error 2
CMakeFiles/Makefile2:116: recipe for target 'CMakeFiles/TryZip.dir/rule' failed
make[1]: *** [CMakeFiles/TryZip.dir/rule] Error 2
Makefile:131: recipe for target 'TryZip' failed
make: *** [TryZip] Error 2
这是我的cmakfile.txt

cmake_minimum_required(VERSION 3.15)
project(TryZip)

if(BOOST_FILESYSTEM)
    include_directories(${BOOST_INCLUDE_DIR})
    link_directories(${BOOST_LIB_DIR})
    add_definitions(-DUSE_BOOST_FILESYSTEM)
else()
    if(MSVC)
        add_definitions(-DFILESYSTEM_EXPERIMENTAL)
    endif()
endif()
if(BOOST_FILESYSTEM)
    if(UNIX)
        find_package(Boost COMPONENTS system filesystem REQUIRED)

        target_link_libraries(${Boost_FILESYSTEM_LIBRARY}
                ${Boost_SYSTEM_LIBRARY})
    endif()
endif()

add_subdirectory(ExternalLibrary/ZipLib)
link_libraries(ExternalLibrary/ZipLib)
include_directories(ExternalLibrary/ZipLib)


set(CMAKE_CXX_STANDARD 17)
add_executable(TryZip main.cpp ExternalLibrary/ZipLib/ZipFile.cpp)

target_link_libraries(TryZip ZipLib)
有人能帮我解决这个问题吗?
我的ZipLib文件夹与我的cmakefile.txt文件位于同一文件夹中。

在这种情况下,调用
链接库()
似乎接受了错误的参数。该命令接受现有CMake目标或库名称的参数。它还与您的
target\u link\u libraries()
调用冗余,因为这已经将
ZipLib
链接到
TryZip

add_subdirectory(ExternalLibrary/ZipLib)

set(CMAKE_CXX_STANDARD 17)
add_executable(TryZip main.cpp)

target_include_directories(TryZip PRIVATE ExternalLibrary/ZipLib)
target_link_libraries(TryZip PRIVATE ZipLib)
请尝试删除对
链接库()
的调用,因为此CMake函数已被弃用,并且非常不鼓励使用。<代码>包含DIDENTIORIONS(/)代码>调用同样被禁止,有利于目标特定的命令,因此考虑使用。p> 假设添加的子目录
ExternalLibrary/ZipLib
包含用于配置
ZipLib
目标的额外
CMakeLists.txt
文件,则不需要再次添加
ZipFile.cpp
文件。如果此文件已在子目录中编译到目标
ZipLib
,则无需将其再次编译到
TryZip

add_subdirectory(ExternalLibrary/ZipLib)

set(CMAKE_CXX_STANDARD 17)
add_executable(TryZip main.cpp)

target_include_directories(TryZip PRIVATE ExternalLibrary/ZipLib)
target_link_libraries(TryZip PRIVATE ZipLib)

编辑:根据您的反馈,它似乎也取决于
pthread
,但不知何故它没有正确链接。您可以尝试将以下内容添加到
ExternalLibrary/ZipLib/CMakeLists.txt
文件(如果该文件不存在)中,以利用CMake的模块: