V
V
Vmedmen2018-09-01 17:36:47
C++ / C#
Vmedmen, 2018-09-01 17:36:47

How to solve the problem of adding Boost when configuring cmake?

Hi all.
I'm trying to connect the boost asio libraries to my project. But I encounter a problem when configuring
Imported targets and dependency information not available for Boost version
Googled this problem for two days, but I could not solve it. I'm just getting started with C++.
New cmake warning about BOOST
CMake finds Boost but the imported targets not ava...
Understood that Boost 1.65 and 1.65.1 require CMake 3.9.3 or newer. However, updating cmake to 3.12.1 gives no results.
Please help or advice on this matter.
System: Ubuntu 18.04
libboost: 1.65.1.0ubuntu1
cmake version 3.12.1 (updated)
Simple project code

#include <iostream>
#include <boost/asio.hpp>

int main() {
    std::cout << "Hello, World!" << std::endl;

    boost::asio::ip::tcp::iostream stream("google.com", "http");
    stream << "GET /ip HTTP/1.1\r\nHost: google.com\r\nConnection: closer\n\r\n";
    std::cout << stream.rdbuf();
    
    return 0;
}

CMakeList.txt
cmake_minimum_required(VERSION 3.12)
project(ticker)

set(CMAKE_CXX_STANDARD 11)

set (BOOST_ROOT "/usr/lib/x86_64-linux-gnu/")

set (Boost_NO_SYSTEM_PATHS ON)
set (Boost_USE_MULTITHREADED ON)
set (Boost_USE_STATIC_LIBS ON)
set (Boost_USE_STATIC_RUNTIME OFF)
set (BOOST_ALL_DYN_LINK OFF)

find_package (Boost REQUIRED COMPONENTS system filesystem)

if (Boost_FOUND)
    include_directories (SYSTEM ${Boost_INCLUDE_DIR})
endif ()

add_executable(ticker main.cpp)

target_link_libraries (ticker ${Boost_LIBRARIES})

When I try to compile I get the following
cmake ticker
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning at /opt/cmake-3.12.1-Linux-x86_64/share/cmake-3.12/Modules/FindBoost.cmake:577 (message):
  Imported targets and dependency information not available for Boost version
  (all versions older than 1.33)
Call Stack (most recent call first):
  /opt/cmake-3.12.1-Linux-x86_64/share/cmake-3.12/Modules/FindBoost.cmake:959 (_Boost_COMPONENT_DEPENDENCIES)
  /opt/cmake-3.12.1-Linux-x86_64/share/cmake-3.12/Modules/FindBoost.cmake:1618 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:14 (find_package)


CMake Warning at /opt/cmake-3.12.1-Linux-x86_64/share/cmake-3.12/Modules/FindBoost.cmake:577 (message):
  Imported targets and dependency information not available for Boost version
  (all versions older than 1.33)
Call Stack (most recent call first):
  /opt/cmake-3.12.1-Linux-x86_64/share/cmake-3.12/Modules/FindBoost.cmake:959 (_Boost_COMPONENT_DEPENDENCIES)
  /opt/cmake-3.12.1-Linux-x86_64/share/cmake-3.12/Modules/FindBoost.cmake:1618 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:14 (find_package)


CMake Error at /opt/cmake-3.12.1-Linux-x86_64/share/cmake-3.12/Modules/FindBoost.cmake:2044 (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:14 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/ivan/Projects/CMakeFiles/CMakeOutput.log".

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2018-09-02
@vt4a2h

All you need to write:

find_package(Boost 1.65.1 REQUIRED)

# ...

include_directories(SYSTEM ${Boost_INCLUDE_DIRS})

# ...

target_link_libraries(myapp ${Boost_LIBRARIES})

Remove everything else related to boost until you understand why it is needed. And don't forget to install boost-dev or boost-devel or libboost-all-dev, I don't remember exactly what it's called in Ubuntu, on the system.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question