我在从 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/