简体   繁体   中英

Unable to find the requested Boost libraries in cmake with conan

I have a problem to compile with cmake using the boost library in c++ from the conan dependencies in a Unix System (Ubuntu)

The sfml library is already implemented and working in the project but the boost library doesn't work and is displaying this message:

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)

Here is my 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

Here is my 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)

I've tried so many solutions but no one is working. All solutions or tips are welcome, thanks !

I think you've forgot to add conan_basic_setup() in your CMakeLists.txt

Look at the # Setting the project 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)

Here is the example of proper usage in readme https://github.com/conan-io/cmake-conan

No need for conanfile.txt, it is generated.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM