【问题标题】:Unable to find the requested Boost libraries in cmake with conan无法使用柯南在 cmake 中找到请求的 Boost 库
【发布时间】:2019-11-24 13:44:42
【问题描述】:

我在使用 c++ 中的 boost 库从 Unix 系统 (Ubuntu) 中的柯南依赖项中使用 cmake 进行编译时遇到问题

sfml 库已经实现并在项目中运行,但 boost 库不起作用并显示此消息:

CMake Error at /usr/share/cmake-3.13/Modules/FindBoost.cmake:2100 (message):
  Unable to find the requested Boost libraries.

  Unable to find the Boost header files.  Please set BOOST_ROOT to the root
  directory containing Boost or BOOST_INCLUDEDIR to the directory containing
  Boost's headers.
Call Stack (most recent call first):
  CMakeLists.txt:13 (find_package)

这是我的 conanfile.txt

[requires]
sfml/2.5.1@bincrafters/stable
boost/1.69.0@conan/stable

[options]
sfml:graphics=True
sfml:window=True
sfml:audio=True
sfml:network=False

[generators]
cmake

这是我的 CMakeLists.txt

# Minimum version of cmake
cmake_minimum_required(VERSION 3.10)

# Setting the project
project(CPP_rtype_2019 CXX)
include(build/conanbuildinfo.cmake)

# Dependencies Sfml
find_package(SFML 2.5.1 EXACT REQUIRED COMPONENTS system window graphics audio)
find_package(Threads REQUIRED)

# Dependencies Boost
find_package(Boost 1.69.0 EXACT REQUIRED COMPONENTS thread system filesystem)
include_directories(${Boost_INCLUDE_DIRS})

# Set the C++11 standard
set(CMAKE_CXX_STANDARD 11)

# Added all .hpp
include_directories(client/include)
include_directories(server/include)

# Added all .cpp
add_executable(r-type_client client/src/Actor.cpp client/src/Character.cpp client/src/Ennemy.cpp client/src/Interface.cpp client/src/Pown.cpp client/src/Projectile.cpp)
add_executable(r-type_server server/src/GameEngine.cpp)

# Added dependencies to compilation
target_link_libraries(r-type_client PRIVATE sfml-audio sfml-system sfml-graphics)
target_link_libraries(r-type_server PRIVATE Boost::thread Boost::system Boost::filesystem)

我尝试了很多解决方案,但没有一个有效。欢迎提供所有解决方案或提示,谢谢!

【问题讨论】:

  • 您是否尝试过针对此question 提到的任何解决方案?
  • 我会说正在使用的 find.cmake 脚本是系统脚本,这可能会出现问题,因为它需要系统级别的 Boost,而不是柯南包。我强烈建议尝试柯南方式(使用conan_basic_setup(TARGETS) 并与目标CONAN_PKG::boost 链接),或者尝试新的生成器cmake_find_package_multi,确保CMAKE_MODULE_PATH 和CMAKE_PREFIX_PATH 指向找到的目录。生成 cmake 脚本。此外,将问题提交给github.com/conan-io/conan 是一种更好的讨论方式。

标签: c++ boost cmake conan


【解决方案1】:

我认为您忘记在 CMakeLists.txt 中添加 conan_basic_setup()

查看# Setting the project

# Minimum version of cmake
cmake_minimum_required(VERSION 3.10)

# Setting the project
project(CPP_rtype_2019 CXX)
include(build/conanbuildinfo.cmake)
conan_basic_setup()

# Dependencies Sfml
find_package(SFML 2.5.1 EXACT REQUIRED COMPONENTS system window graphics audio)
find_package(Threads REQUIRED)

# Dependencies Boost
find_package(Boost 1.69.0 EXACT REQUIRED COMPONENTS thread system filesystem)
include_directories(${Boost_INCLUDE_DIRS})

# Set the C++11 standard
set(CMAKE_CXX_STANDARD 11)

# Added all .hpp
include_directories(client/include)
include_directories(server/include)

# Added all .cpp
add_executable(r-type_client client/src/Actor.cpp client/src/Character.cpp client/src/Ennemy.cpp client/src/Interface.cpp client/src/Pown.cpp client/src/Projectile.cpp)
add_executable(r-type_server server/src/GameEngine.cpp)

# Added dependencies to compilation
target_link_libraries(r-type_client PRIVATE sfml-audio sfml-system sfml-graphics)
target_link_libraries(r-type_server PRIVATE Boost::thread Boost::system Boost::filesystem)

【讨论】:

    【解决方案2】:

    这是自述文件https://github.com/conan-io/cmake-conan中正确使用的示例

    不需要conanfile.txt,自己生成。

    cmake_minimum_required(VERSION 3.5)
    project(FormatOutput CXX)
    
    list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
    list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
    
    if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
      message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
      file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.16.1/conan.cmake"
                    "${CMAKE_BINARY_DIR}/conan.cmake"
                    EXPECTED_HASH SHA256=396e16d0f5eabdc6a14afddbcfff62a54a7ee75c6da23f32f7a31bc85db23484
                    TLS_VERIFY ON)
    endif()
    
    include(${CMAKE_BINARY_DIR}/conan.cmake)
    
    conan_cmake_configure(REQUIRES 
                          boost/1.69.0
                          GENERATORS cmake_find_package)
    
    conan_cmake_autodetect(settings)
    
    conan_cmake_install(PATH_OR_REFERENCE .
                        BUILD missing
                        REMOTE conancenter
                        SETTINGS ${settings})
    
    find_package(Boost 1.69.0 EXACT REQUIRED COMPONENTS thread system filesystem)
    
    add_executable(main main.cpp)
    target_link_libraries(main 
         Boost::thread 
         Boost::system 
         Boost::filesystem)
    

    【讨论】:

      猜你喜欢
      • 2019-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-21
      • 2014-08-02
      • 1970-01-01
      相关资源
      最近更新 更多