Search code examples
c++makefilecmakeclang

ld: library not found for -lbitcoin


I am trying to add libbitcoin library to my c++ project. I am using Cmake. I found an example for a configuration here: Use libbitcoin in CLion. Here is my CMakeLists.txt file:

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 does not throw any errors on save, but when compiling, I am getting ld: library not found for -lbitcoin error. Is there is sotheming I am missing here?


Solution

  • Use the IMPORTED_TARGET option to pkg_check_modules. This option generates a CMake target you can link against, and it will make sure to set all relevant variables for you.

    pkg_check_modules(LIB_BITCOIN REQUIRED IMPORTED_TARGET libbitcoin)
    target_link_libraries(vuchain PRIVATE PkgConfig::LIB_BITCOIN)