简体   繁体   中英

Could NOT find Boost (missing: system) (found suitable versiHow on "1.78.0", minimum required is "1.78.0")

How to run boost asio with cmake? Havint this simple project layout:

c1
├── c1
│   └── main.cpp
└── CMakeLists.txt

CMakeLists.txt :

cmake_minimum_required(VERSION 3.20.0)
project(c1)

add_executable(c1 c1/main.cpp)
include_directories(.)

set(BOOST_ROOT /usr/local/boost_1_78_0)
find_package(Boost 1.78.0 REQUIRED COMPONENTS system)
target_include_directories(c1 PUBLIC ${Boost_INCLUDE_DIR})
target_link_libraries(c1 LINK_PUBLIC ${Boost_LIBRARIES})

and main.cpp :

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

int main(){
    boost::asio::io_context io;
    boost::asio::steady_timer t(io, boost::asio::chrono::seconds(5));
    t.wait();
    std::cout << "Hello world!" << std::endl;
}

I am getting this cmake error:

CMake Error at /usr/local/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find Boost (missing: system) (found suitable version "1.78.0",
  minimum required is "1.78.0")
Call Stack (most recent call first):
  /usr/local/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/share/cmake-3.22/Modules/FindBoost.cmake:2360 (find_package_handle_standard_args)
  CMakeLists.txt:8 (find_package)

I am not sure if I understand it correclty, but it is trying to find suitable version 1.78.0 , but it found 1.78.0 , so what is the problem?

Also before that, there was a warning:

CMake Warning at /usr/local/share/cmake-3.22/Modules/FindBoost.cmake:1369 (message):
  New Boost version may have incorrect or missing dependencies and imported
  targets
Call Stack (most recent call first):
  /usr/local/share/cmake-3.22/Modules/FindBoost.cmake:1492 (_Boost_COMPONENT_DEPENDENCIES)
  /usr/local/share/cmake-3.22/Modules/FindBoost.cmake:2102 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:8 (find_package)

So what should I do?

EDIT: the system library is at:

/usr/local/boost_1_78_0/boost/system

and the debug output of where is cmake looking:

-- [ /usr/local/share/cmake-3.22/Modules/FindBoost.cmake:2053 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = "/usr/local/boost_1_78_0/lib;/usr/local/boost_1_78_0/stage/lib;/usr/local/boost_1_78_0/lib;/usr/local/boost_1_78_0/../lib;/usr/local/boost_1_78_0/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib"
-- [ /usr/local/share/cmake-3.22/Modules/FindBoost.cmake:2054 ] _boost_LIBRARY_SEARCH_DIRS_DEBUG = "/usr/local/boost_1_78_0/lib;/usr/local/boost_1_78_0/stage/lib;/usr/local/boost_1_78_0/lib;/usr/local/boost_1_78_0/../lib;/usr/local/boost_1_78_0/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib"

-- [ /usr/local/share/cmake-3.22/Modules/FindBoost.cmake:2239 ] Searching for SYSTEM_LIBRARY_RELEASE: boost_system-gcc10-mt-1_78;boost_system-gcc10-mt;boost_system-gcc10-mt;boost_system-mt-1_78;boost_system-mt;boost_system-mt;boost_system-mt;boost_system
-- [ /usr/local/share/cmake-3.22/Modules/FindBoost.cmake:2294 ] Searching for SYSTEM_LIBRARY_DEBUG: boost_system-gcc10-mt-d-1_78;boost_system-gcc10-mt-d;boost_system-gcc10-mt-d;boost_system-mt-d-1_78;boost_system-mt-d;boost_system-mt-d;boost_system-mt;boost_system

Yet I cannot understand, why the cmake cannot find that library.

Looks like you forgot to build the Boost libraries.

Many Boost libraries are, or can be , header-only, but many aren't.

I think the CMake FindBoost components only bother with the libraries that require building. So, if you name system as a required component, you're telling CMake that you need to link it, and it looks for the built libraries.

The built libraries are typically under stage/lib/ eg

/home/sehe/custom/boost/stage/lib/libboost_system.a
/home/sehe/custom/boost/stage/lib/libboost_system.so
/home/sehe/custom/boost/stage/lib/libboost_system.so.1.78.0

However, if you didn't build the library, it will be missing.

See https://www.boost.org/doc/libs/1_78_0/more/getting_started/unix-variants.html

Don't waste your time trying to compile Boost, this is not the problem here.

Like Tsyvarev said, since version 1.69 if you are using only system or any other header-only component (not requiring build) you must remove keyword COMPONENT

find_package(Boost 1.80.0 REQUIRED)

# ...Nothing more

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