Closed abhishekmishra closed 4 years ago
I have created a repo with test code to help reproduce this error -> https://github.com/abhishekmishra/vcpkg_libarchive_issue_8839. It has a cmake build which works on windows+vcpkg and linux+pkgconfig but fails with linux+vcpkg. Instructions to reproduce are in the README.
Hi @abhishekmishra, function crc32
and deflateInit2
need link to zlib. You need add find_package(ZLIB REQUIRED)
to CMakeLists. Due to libarchive depends on zlib, zlib should be placed behind libarchive in target_link_libraries
. Like this:
find_package(ZLIB REQUIRED)
find_path(LIBARCHIVE_INCLUDE_DIR archive.h)
find_library(LIBARCHIVE_LIBRARY archive)
include_directories(${LIBARCHIVE_INCLUDE_DIR})
target_link_libraries(vcpkg_libarchive_issue_8839 PRIVATE ${LIBARCHIVE_LIBRARY} ZLIB::ZLIB)
Hi @abhishekmishra, function
crc32
anddeflateInit2
need link to zlib. You need addfind_package(ZLIB REQUIRED)
to CMakeLists. Due to libarchive depends on zlib, zlib should be placed behind libarchive intarget_link_libraries
. Like this:find_package(ZLIB REQUIRED) find_path(LIBARCHIVE_INCLUDE_DIR archive.h) find_library(LIBARCHIVE_LIBRARY archive) include_directories(${LIBARCHIVE_INCLUDE_DIR}) target_link_libraries(vcpkg_libarchive_issue_8839 PRIVATE ${LIBARCHIVE_LIBRARY} ZLIB::ZLIB)
Thanks a lot, this worked for me.
Describe the bug I have a cmake build, which uses vcpkg toolchain and links an executable to the libarchive library as one of it's dependencies. The build works fine on Windows x64 and Macos. However when I try the same build on an x64 linux (namely Ubuntu 18.04), I get linker errors. This is my first time using vcpkg so I might be doing something incorrect here.
Here's the relevant section of my cmake build:
Environment
libarchive[bzip2]:x64-linux BZip2 support
libarchive[libxml2]:x64-linux Libxml2 support
libarchive[lz4]:x64-linux LZ4 support
libarchive[lzma]:x64-linux LZMA support
libarchive[lzo]:x64-linux LZO support
libarchive[openssl]:x64-linux OpenSSL support
liblzma:x64-linux 5.2.4-2 Compression library with an API similar to that ...
libxml2:x64-linux 2.9.9-4 Libxml2 is the XML C parser and toolkit develope...
lz4:x64-linux 1.9.2 Lossless compression algorithm, providing compre...
lzo:x64-linux 2.10-4 Lossless data compression library
zlib:x64-linux 1.2.11-5 A compression library
To Reproduce Steps to reproduce the behavior:
/root/vcpkg/installed/x64-linux/debug/lib/libarchive.a(archive_write_add_filter_gzip.c.o): In function
archive_compressor_gzip_open': /root/vcpkg/buildtrees/libarchive/src/fa3b23efe3-1e0b785ee8/libarchive/archive_write_add_filter_gzip.c:242: undefined reference to
deflateInit2_' /root/vcpkg/installed/x64-linux/debug/lib/libarchive.a(archive_write_add_filter_gzip.c.o): In functionarchive_compressor_gzip_close': /root/vcpkg/buildtrees/libarchive/src/fa3b23efe3-1e0b785ee8/libarchive/archive_write_add_filter_gzip.c:333: undefined reference to
deflateEnd' /root/vcpkg/installed/x64-linux/debug/lib/libarchive.a(archive_write_add_filter_gzip.c.o): In functiondrive_compressor': /root/vcpkg/buildtrees/libarchive/src/fa3b23efe3-1e0b785ee8/libarchive/archive_write_add_filter_gzip.c:374: undefined reference to
deflate' collect2: error: ld returned 1 exit statusExpected behavior The build should succeed.