-1

I'm getting this error

CMake Error at /usr/local/share/cmake-3.5/Modules/FindBoost.cmake:1657 (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.

In my CMake I have

if(Boost_FOUND)
  include_directories(${Boost_INCLUDE_DIRS})
  message("\n\n Boost found \n\n") 
 endif()

... and then

 target_link_libraries(${files}
    ${catkin_LIBRARIES}
    ${MY_LIB}
    ${MY_LIB}
    ${gsl_LIBRARIES}
    # ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_REGEX_LIBRARY}
    ${Boost_LIBRARIES} #new for catkin ...)

I even tried find_package( Boost REQUIRED COMPONENTS components), find_package( Boost REQUIRED), find_package(Bost 1.60.0 COMPONENTS filesystem regex), or find_package(Boost REQUIRED COMPONENTS system) ... but did not work

For info I installed boost like

$ cd  ~/soft/lib/boost/boost_1_60_0
$ /bootstrap.sh 
$ ./b2

.. at the end the system prompted

The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:

    /home/~/soft/lib/boost/boost_1_60_0

The following directory should be added to linker library paths:

    /home/~/soft/lib/boost/boost_1_60_0/stage/lib 

I just added these two lines to my .bashrc and sourced it.

export INCLUDE="/home/~/soft/lib/boost/boost_1_60_0:$INCLUDE"
export LIBRARY_PATH="/home/~/soft/lib/boost/boost_1_60_0/stage/lib:$LIBRARY_PATH"

For info I also tried sudo apt-get install libbost-all-dev, but still nothing. Any idea please?

SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
Courier
  • 920
  • 2
  • 11
  • 36
  • What about setting `BOOST_ROOT` variable, as error message advices? – Tsyvarev May 18 '16 at 10:37
  • Did not get the point. Can you please clarify? – Courier May 18 '16 at 10:38
  • Set `BOOST_ROOT` variable to root directory of Boost installation. In your case it should be something like `export BOOST_ROOT=/home/~/soft/lib/boost/boost_1_60_0`. – Tsyvarev May 18 '16 at 10:43
  • It is better (reaching 100% ) but still have issues at the end; lot of `undefined reference to boost::xy.` Eg. `undefined reference to boost::this_thread::interruption_point()` Am trying now adding export BOOST_LIBS=... – Courier May 18 '16 at 10:50
  • but still problem if I try `find_package( Boost REQUIRED COMPONENTS components )`. It says `Boost include path: /home/~/soft/lib/boost/boost_1_60_0 Could not find the following Boost libraries: boost_components` – Courier May 18 '16 at 11:04

1 Answers1

2

One simple thing that looks strange in your output is the ~:

 /home/~/soft/lib/boost/boost_1_60_0/stage/lib 

Shouldn't that be either:

 ~/soft/lib/boost/boost_1_60_0/stage/lib 

or

 /home/<your username>/soft/lib/boost/boost_1_60_0/stage/lib 

I am not sure how Cmake handles special shell characters like ~ but I think you would be better off if you used an absolute path, at least for testing. For the record, not even bash handles that:

$ ls /home/~/
ls: cannot access /home/~: No such file or directory

I use Boost and Cmake on Ubuntu 14.04 without problems. I am using the following in my projects, and everything works as expected:

SET (BOOST_ROOT "/opt/boost/boost_1_57_0")
SET (BOOST_INCLUDEDIR "/opt/boost/boost-1.57.0/include")
SET (BOOST_LIBRARYDIR "/opt/boost/boost-1.57.0/lib")
SET (BOOST_MIN_VERSION "1.55.0")
set (Boost_NO_BOOST_CMAKE ON)
FIND_PACKAGE(Boost ${BOOST_MIN_VERSION} REQUIRED)
if (NOT Boost_FOUND)
  message(FATAL_ERROR "Fatal error: Boost (version >= 1.55) required.")
else()
  message(STATUS "Setting up BOOST")
  message(STATUS " Includes - ${Boost_INCLUDE_DIRS}")
  message(STATUS " Library  - ${Boost_LIBRARY_DIRS}")
  include_directories(${Boost_INCLUDE_DIRS})
  link_directories(${Boost_LIBRARY_DIRS})
endif (NOT Boost_FOUND)

This was using Ubuntu 14.04 and cmake version 2.8.

You might want to pick BOOST_ROOT from an environment variable or otherwise, to avoid hardcoding your setup to a particular machine.

The full makefile in question is here.

If you want to use the Boost version that comes with your distribution of Ubuntu (the one you installed through the package manager), something like this should work:

FIND_PACKAGE( Boost )
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )

ADD_EXECUTABLE( yourProgram sourceFile.cpp )

TARGET_LINK_LIBRARIES( yourProgram ${Boost_LIBRARIES} )

If you are having issues with this, try setting the paths in the approach suggested above to /usr/include/ and /usr/lib/ or /usr/local/include and /usr/local/lib (depending on where Boost lives on your system). Though if you have to do this something seems wrong :D

Please also check these answers on how to use Boost and CMAKE and how to check your Boost version

Community
  • 1
  • 1
paul-g
  • 3,797
  • 2
  • 21
  • 36
  • It seems better. But still have other issues with opencv library. Try to fix that first and then revert yo you to confirm your solution. Thanks! – Courier May 18 '16 at 12:28
  • 1
    It seems working but still am getting: `warning: libboost_system.so.1.54.0, needed by /opt/ros/indigo/lib/libimage_transport.so, may conflict with libboost_system.so.1.60.` – Courier May 19 '16 at 03:38
  • 1
    looks like libimage transport is compiled against boost 1.54. at runtime you are probably loading boost 1.60 (through your library path). hence the warning. The way to fix it is to compile everything against the same boost version. So either use 1.54 for your project or recompile the other lib with 1.60. but this is digressing a bit from the original topic IMHO :) you could post another question – paul-g May 19 '16 at 08:23
  • because I also used `apt-get install libboost-all-dev` I think – Courier May 19 '16 at 08:31
  • Thus, another question what is the best way to install boost? I think I will clean install ubuntu and remake everything from scratch... – Courier May 19 '16 at 08:33
  • This is not a problem of installing Boost. But the fact that you have two objects compiled against different versions of boost. As I said there are two options: either use the ubuntu default boost libraries for your project as well (see my updated answer on how to use the default version) or use the `1.60` version to recompile `libimage_transport`. – paul-g May 19 '16 at 09:42
  • Could you accept the answer since it seems to have solved your original question? – paul-g May 19 '16 at 21:32