【问题标题】:Use libbitcoin in CLion在 CLion 中使用 libbitcoin
【发布时间】:2017-09-28 23:59:15
【问题描述】:

我不是C++程序员,前段时间才做了一门课程。使用自制软件我安装了 libbitcoin,并希望我可以像引用 boost 库一样引用该库。我还意识到 /usr/local/bin 中没有指向酒窖的链接。 我想我可以通过使用绝对路径让它工作,但我正在寻找处理我刚才提到的这个星座的正确方法。

当前 CMake:

cmake_minimum_required(VERSION 2.8.4)

project(cplusplus)

message(STATUS "start running cmake...")

find_package(boost 1.65.1 COMPONENTS system filesystem REQUIRED)
find_package(libbitcoin 3.3.0 COMPONENTS system filesystem REQUIRED)

message("system: ${CMAKE_SYSTEM_PREFIX_PATH}")
find_library(LIB_BITCOIN libbitcoin)
message("bitcoin: ${LIB_BITCOIN}")

if(Boost_FOUND)
    message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
    message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
    message(STATUS "Boost_VERSION: ${Boost_VERSION}")
    include_directories(${Boost_INCLUDE_DIRS})
 endif()

 add_executable(cplusplus main.cpp)

 if(Boost_FOUND)
     target_link_libraries(cplusplus ${Boost_LIBRARIES})
 endif()

目前我收到以下错误:

/Applications/CLion.app/Contents/bin/cmake/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /Users/johndow/Documents/Workspace/bitcoin-code/cplusplus
-- start running cmake...
-- Boost version: 1.65.1
CMake Error at CMakeLists.txt:8 (find_package):
  By not providing "Findlibbitcoin.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "libbitcoin", but CMake did not find one.

  Could not find a package configuration file provided by "libbitcoin"
  (requested version 3.3.0) with any of the following names:

  libbitcoinConfig.cmake
  libbitcoin-config.cmake

  Add the installation prefix of "libbitcoin" to CMAKE_PREFIX_PATH or set
  "libbitcoin_DIR" to a directory containing one of the above files.  If
  "libbitcoin" provides a separate development package or SDK, be sure it has
  been installed.


-- Configuring incomplete, errors occurred!
See also "/Users/johndoe/Documents/Workspace/bitcoin-code/cplusplus/cmake-build-debug/CMakeFiles/CMakeOutput.log".

[Finished]

【问题讨论】:

    标签: c++ homebrew


    【解决方案1】:

    您似乎在 CMakeLists 文件中对 libbitcoin 库进行了双重查找。您首先通过以下方式查找它:

    find_package(libbitcoin ...) 
    

    然后通过

    find_library(LIB_BITCOIN libbitcoin)
    

    Cmake 对 find_package() 子句不满意(如您的错误消息所述),因为 libbitcoin 本身不提供 cmake 配置。你有很多方法可以解决它,只有其中两种:

    1. 删除 find_package() 并仅使用 find_library(),我认为这是更简单的方法,您的项目应该以这种方式工作

    2. 自行为 libbitcoin 提供 cmake 配置。很好的介绍如何做到这一点是here(无论如何都很好读): https://cmake.org/Wiki/CMake:How_To_Find_Libraries

    【讨论】:

      【解决方案2】:

      据我所知,目前libbitcoin导出任何<libbitcoin>Config.cmake 包。

      但它确实导出了一个libbitcoin.pc 文件以供pkg-config 通用使用。

      即:/usr/local/lib/pkgconfig/libbitcoin.pc

      如果您通过调用 pkg-config --cflags libbitcoin 获得结果,那么它就在那里。

      然后你可以在你的CMakeLists.txt中加入这样的东西:

      #use this if libbitcoin is installed to some custom location
      set(ENV{PKG_CONFIG_PATH} "/path/to/libbitcoin/pkgconfig/:$ENV{PKG_CONFIG_PATH}")
      
      #then later..
      find_package(PkgConfig REQUIRED)
      pkg_check_modules(LIB_BITCOIN REQUIRED libbitcoin) 
      
      #then later..
      target_link_libraries(${PROJECT_NAME} PRIVATE ${LIB_BITCOIN_LIBRARIES})
      target_include_directories(${PROJECT_NAME} PRIVATE ${LIB_BITCOIN_INCLUDE_DIRS})
      

      这应该引入boost,使libbitcoin includes 可见并解决各种编译器和链接器问题。

      (或者如果你觉得很生气,你可以随时使用this gist)。

      【讨论】:

        猜你喜欢
        • 2015-09-18
        • 1970-01-01
        • 1970-01-01
        • 2016-04-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多