我正在尝试将libbitcoin库添加到我的c ++项目中。我正在使用Cmake。我在这里找到了一个配置示例:Use libbitcoin in CLion。这是我的CMakeLists.txt文件:
cmake_minimum_required(VERSION 3.14)
project(vuchain)
set(CMAKE_CXX_STANDARD 11)
set(ENV{PKG_CONFIG_PATH} "/usr/local/libbitcoin/lib/pkgconfig/:$ENV{PKG_CONFIG_PATH}")
find_package(PkgConfig REQUIRED)
find_library(libbitcoin PKG_CONFIG_PATH)
pkg_check_modules(LIB_BITCOIN REQUIRED libbitcoin)
add_executable(vuchain main.cpp user.h main.h ./HASH/HASH.cpp ./HASH/HASH.h ./HASH/sha256.cpp ./HASH/sha256.h transaction.h transaction_list.h block.h HASH/sha256.cpp HASH/sha256.h blockchain.cpp blockchain.h)
target_link_libraries(vuchain PRIVATE ${LIB_BITCOIN_LIBRARIES})
target_include_directories(vuchain PRIVATE ${LIB_BITCOIN_INCLUDE_DIRS})
CMakeLists.txt在保存时不会引发任何错误,但是在编译时,出现ld: library not found for -lbitcoin
错误。我在这里想念吗?
将IMPORTED_TARGET
选项用于pkg_check_modules
。此选项将生成可链接的CMake目标,并确保为您设置所有相关变量。
pkg_check_modules(LIB_BITCOIN REQUIRED IMPORTED_TARGET libbitcoin)
target_link_libraries(vuchain PRIVATE PkgConfig::LIB_BITCOIN)