Search code examples
c++boostcmakeconan

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 !


Solution

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