c++ - 无法在带有 conan 的 cmake 中找到请求的 Boost 库

标签 c++ boost cmake conan

我在从 Unix 系统 (Ubuntu) 中的 conan 依赖项中使用 c++ 中的 boost 库使用 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)

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

最佳答案

我想你忘了在你的 CMakeLists.txt 中添加 conan_basic_setup()

查看#设置项目 block

# 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)

关于c++ - 无法在带有 conan 的 cmake 中找到请求的 Boost 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59018284/

相关文章:

mysql - 无法从cygwin中的源代码构建mysql连接器/c(libmysql)

c++ - 用于插入集合的配对相等运算符重载

c++ - 从另一个 Nan::ObjectWrap 返回一个 Nan::ObjectWrap

python - boost::python 具有静态工厂构造函数和 std::unique_ptr 的纯虚拟基类

c++ - 如何在 Ubuntu 14.04 的 QT Creator 中使用 Boost 库

c++ - 使用 VS_DEBUGGER_ENVIRONMENT 设置的 PATH 环境调试 CMake Visual Studio 项目

c++ - 构建本身就是 shared_ptr 类型的模板化容器

c++ - WaitForSingleObject 在 XP 中获取他的信号量,但在 Vista 中没有

c++ - 如何使用 boost::preprocessor 解压序列?

c++ - cmake:查找/添加 Visual Studio 或 windows sdk 库和头文件的正确方法?