3

I am currently having a problem with Boost. During CMake stage, it stated clearly that boost was found:

-- Boost version: 1.61.0
-- Found the following Boost libraries:
--   filesystem
--   program_options
--   iostreams
--   timer
--   system
--   regex

But during the make stage from the generated Makefile:

Timer.h(26): catastrophic error: cannot open source file "boost/timer/timer.hpp"
  #include <boost/timer/timer.hpp>
[..]                                  ^

Function.h(29): catastrophic error: cannot open source file "boost/ptr_container/ptr_map.hpp"
  #include <boost/ptr_container/ptr_map.hpp>
[..]

basically, it doesn't seem like Makefile found any header for boost. I have even gone and declare Boost_INCLUDEDIR and Boost_LIBRARYDIR - case sensitive. Doesn't look like it helps.

What could be the possible cause? Could it be some conflicts between the compiler, i.e. gcc/icc and the cmake generator? (Pure guess - I am not expertised in this area...)

EDIT: This is the process of find boost in the CMakeLists.txt file: http://pastebin.com/7m3yAYk5 and the FindBOOST.cmake is here: https://github.com/Kitware/CMake/blob/master/Modules/FindBoost.cmake

  • 1
    Please edit your question and add the content of your `CMakeLists.txt` looking for Boost. It is not possible to answer your question without knowing how you are searching and using Boost – rocambille Jan 03 '17 at 09:36
  • 4
    Did you have this `include_directories(SYSTEM ${Boost_INCLUDE_DIR})` – Danh Jan 03 '17 at 09:38

1 Answers1

6

Finding a library and including it are two different things.

You will need to not only find Boost, but include it's headers and link to its libraries. A simple CMakeLists.txt example:

FIND_PACKAGE( Boost 1.61 COMPONENTS filesystem program_options iostreams timer REQUIRED )
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )

ADD_EXECUTABLE( myProgram myMain.cpp )

TARGET_LINK_LIBRARIES( myProgram ${Boost_LIBRARIES} )

If you have already done this, please update your question to include that information.

Cinder Biscuits
  • 4,880
  • 31
  • 51
  • 1
    This doesn't work for me on Windows with `find_package(Boost 1.70.0 REQUIRED COMPONENTS graph) ` on Cmake 3.17. Still get cannot open source file... Any ideas? – ktnr Oct 31 '20 at 21:34