我想我错过了一些非常简单的东西,但这是我的设置:
我正在使用conan安装zstandard:
[requires]
...
zstd/1.5.1
配置如下:
[settings]
os=Linux
arch=x86_64
build_type=Release
compiler=clang
compiler.version=12
compiler.libcxx=libstdc++
[env]
CC=/usr/bin/clang-12
CXX=/usr/bin/clang++-12
我的CMakeLists.txt
如下:
set(LIBRARY_ZSTDSTREAM_SOURCES
zstdstream.cpp
)
set(LIBRARY_ZSTDSTREAM_HEADERS
circularbuffer.h
zstdstream.h
)
add_library(${LIBRARY_ZSTDSTREAM_NAME} STATIC
${LIBRARY_ZSTDSTREAM_SOURCES}
${LIBRARY_ZSTDSTREAM_HEADERS})
target_link_libraries(${LIBRARY_ZSTDSTREAM_NAME} PUBLIC
${CONAN_ZSTD}
${LIBRARY_FORMAT_NAME}
)
target_include_directories(${LIBRARY_ZSTDSTREAM_NAME} PUBLIC
"./"
"${CMAKE_BINARY_DIR}/configured_files/include"
)
我得到的错误消息如下:
zstdstream.cpp:(.text+0x3b): undefined reference to `ZSTD_getErrorName'
/usr/bin/ld: ../../lib/libzstdstream.a(zstdstream.cpp.o): in function `common::zstdstream::cstream::cstream()':
zstdstream.cpp:(.text+0xc5): undefined reference to `ZSTD_createCStream'
/usr/bin/ld: ../../lib/libzstdstream.a(zstdstream.cpp.o): in function `common::zstdstream::cstream::~cstream()':
zstdstream.cpp:(.text+0xd8): undefined reference to `ZSTD_freeCStream'
/usr/bin/ld: zstdstream.cpp:(.text+0xe3): undefined reference to `ZSTD_isError'
/usr/bin/ld: ../../lib/libzstdstream.a(zstdstream.cpp.o): in function `common::zstdstream::cstream::init(int)':
zstdstream.cpp:(.text+0x148): undefined reference to `ZSTD_initCStream'
/usr/bin/ld: zstdstream.cpp:(.text+0x153): undefined reference to `ZSTD_isError'
我通过设置VERBOSE=1
运行makefile:来检查链接器
-Wl,-rpath,/home/worker/.conan/data/zstd/1.5.1/_/_/package/4d1e52cb9a38d07b5e682edec92bb71d7afcd534/lib:
-L/home/worker/.conan/data/zstd/1.5.1/_/_/package/4d1e52cb9a38d07b5e682edec92bb71d7afcd534/lib
所以zstd库就在那里,并且链接正确。
我对发生的事情很困惑。
CMakeToolchain
&CMakeDeps
发生器:
conanfile.txt:
[requires]
zstd/1.5.1
[generators]
CMakeToolchain
CMakeDeps
CMakeLists.txt:
cmake_minimum_required(VERSION 3.15)
project(foo)
find_package(zstd REQUIRED)
add_library(bar ...)
target_link_libraries(bar PRIVATE $<IF:$<TARGET_EXISTS:zstd::libzstd_shared>,zstd::libzstd_shared,zstd::libzstd_static>)
安装依赖项&构建:
mkdir build && cd build
conan install .. -s build_type=Release -b missing
cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release
我无法让conan工作。${CONAN_ZSTD}
可能不是正确的变量名称,并且我找不到正确的变量名。
相反,我使用了CMake的fetchContent,它对我有效:
include(FetchContent)
FetchContent_Declare(zstd
GIT_REPOSITORY "https://github.com/facebook/zstd"
GIT_TAG "dev"
)
FetchContent_MakeAvailable(
zstd
)