8

I have the latest cmake 3.0.2 compiled from sources, also libboost-all-dev installed. And find_package(Boost) can't find it. Here is output of cmake:

Unable to find the requested Boost libraries.

Unable to find the Boost header files. Please set BOOST_ROOT to the root 
directory containing Boost of BOOST_INCLUDEDIR to the directory containing
Boost's headers.

Do I need to manually set any variables after installing Boost to get it visible for cmake?

Thanks.

4 Answers 4

6

What version of libboost-all-dev are you using? I assume you are using v1.53.0.

Try installing libboost1.54-all-dev instead.

2
  • 2
    use sudo apt-get install libboost-all-dev Jul 25, 2016 at 11:32
  • @JithinPavithran thank you it helped!
    – littleguga
    Jun 26, 2020 at 17:30
3

In 14.04 (and probably earlier) to 16.04, I could use these:

find_package( Boost COMPONENTS filesystem system REQUIRED )

include_directories(
    ${BOOST_INCLUDE_DIRS}
)

target_link_libraries(${PROJECT_NAME}
    ${Boost_FILESYSTEM_LIBRARY}
    ${Boost_SYSTEM_LIBRARY}
}

If you only need the headers, then you do not need to specify any component and no target_link_libraries():

find_package( Boost REQUIRED )

include_directories(
    ${BOOST_INCLUDE_DIRS}
)

With 16.10, I had to make sure to install libboost-all-dev so my code would continue to compile on Ubuntu.

sudo apt-get install libboost-all-dev

Previous versions worked with just libboost-dev, somehow. Although it looks like you already had that part figured out, I just wanted to make sure it was clearly mentioned that there was a recent change in that regard.

2

Thanks, Rohith.

As an alternative solution, I downloaded and built the latest version of boost and added BOOST_ROOT variable in ~/.profile like this:

export BOOST_ROOT=$HOME/work/boost_1_57_0

Note, that boost has to be built if you are using it's non-header libraries.

1

I also meet such awkward situation in ubuntu...

My solution is simply not use find_package but adding the libraries in the link process

target_link_libraries( your_program boost_system boost_filesystem ... )

The bad things is that cmake cannot examine the existence of the boost library. However, it simply works.

Hope someone can figure out a better solution.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .