0

I have installed the libboost-all-dev packaged on Ubuntu.

Cmake 3.10.2 can find boost but not "boost_core".

When I change the find package line to:

find_package(Boost REQUIRED COMPONENTS core)

Then it complains that it can't find "boost_core".

I actually just need boost/iterator...

How to make cmake find that?

Thanks.

CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(test_boost_iterator)

set(CMAKE_CXX_STANDARD 11)

find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
add_definitions( "-DHAS_BOOST" )

add_executable(test_boost_iterator main.cpp)

Success message (before replacing the find_package line):

-- Boost version: 1.65.1
-- Configuring done
-- Generating done

Error message (after replacing the find_package line)

  Unable to find the requested Boost libraries.

  Boost version: 1.65.1

  Boost include path: /usr/include

  Could not find the following Boost libraries:

          boost_core

  No Boost libraries were found.  You may need to set BOOST_LIBRARYDIR to the
  directory containing Boost libraries or BOOST_ROOT to the location of
  Boost.
Call Stack (most recent call first):
  CMakeLists.txt:6 (find_package)
2
  • In your code snippet you didn't specify COMPONENTS for find_package.
    – NuPagadi
    Commented May 8, 2018 at 20:08
  • Yea. That works before I change the find_package line to find_package(Boost REQUIRED COMPONENTS core)
    – R zu
    Commented May 8, 2018 at 20:08

1 Answer 1

1

As I know there is no such a boost library core. You can check if a library should be linked here. And Boost.Iterator is a header-only library, so you don't need to link anything. Just include <boost/iterator/...>. If you can't include, check whether these includes actually exist in your local boost distro.

I checked it for boost::counting_iterator<int> and all works well for me.

2
  • This works without using cmake. But boost can be in non-standard locations, especially for installation without admin rights.
    – R zu
    Commented May 9, 2018 at 3:42
  • If it is in non-standard location, specify it as custom include directory. I don't think FindBoost will find it, if it is located at some esoteric place. Can you tell what your problem is? Why should you change find_package(Boost REQUIRED)?
    – NuPagadi
    Commented May 9, 2018 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.