Search code examples
c++boostcmake

Error "Could not find Boost" (missing: context headers)


I've added boost like this: "-DBoost_INCLUDE_DIR=/boost_1_71_0" and this is what I get:

Could NOT find Boost (missing: context headers) (found suitable version "1.71.0", minimum required is "1.71")

Cmake can determine boost version but cannot find boost at the same time! Is there a way for me to fix it?

This is how I include boost in my cmake file. Nothing fancy in here.

find_package(Boost 1.71 COMPONENTS context headers REQUIRED)

Solution

  • Boost context and headers are header only libraries and therefore do not need to be mentioned in the find_packages call. Do a simple find_package(Boost 1.71 REQUIRED) and you are done. Later you can reference the Boost header directory either with Boost::boost or Boost::headers in your target_link_librariescommand.