Thursday, July 28, 2022

[SOLVED] Could not find a package configuration file provided by "boost_json"

Issue

While following this link to setup boost for json parsing, I am unable to find the boost json component.

Link: href="https://stackoverflow.com/questions/67146394/using-boostjson-static-library-with-cmake">Using boost::json static library with cmake

Here's my CMakeLists.txt:

cmake_minimum_required(VERSION 3.9)

set (CMAKE_CXX_STANDARD 14)

set( Boost_USE_STATIC_LIBS ON )
#set( Boost_USE_MULTITHREADED ON )
#set( Boost_USE_STATIC_RUNTIME OFF )

find_package( Boost REQUIRED COMPONENTS json )

if ( Boost_FOUND )
    include_directories( ${Boost_INCLUDE_DIRS} )
else()
    message( FATAL_ERROR "Required Boost packages not found. Perhaps add -DBOOST_ROOT?" )
endif()

add_executable (test main.cc)


target_include_directories(test PUBLIC ${Boost_INCLUDE_DIRS})

target_link_libraries(test PUBLIC Boost::boost
                                  Boost::json)

Error:

CMake Error at /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake:117 (find_package):
  Could not find a package configuration file provided by "boost_json"
  (requested version 1.71.0) with any of the following names:

    boost_jsonConfig.cmake
    boost_json-config.cmake

  Add the installation prefix of "boost_json" to CMAKE_PREFIX_PATH or set
  "boost_json_DIR" to a directory containing one of the above files.  If
  "boost_json" provides a separate development package or SDK, be sure it has
  been installed.
Call Stack (most recent call first):
  /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake:182 (boost_find_component)
  /usr/share/cmake-3.16/Modules/FindBoost.cmake:443 (find_package)
  CMakeLists.txt:11 (find_package)


-- Configuring incomplete, errors occurred

How do I resolve this error? I did go through some of the posts describing similar issues with boost but nothing worked.


Solution

Boost JSON was introduced in version 1.75.0. It's not available in version 1.71.0. You need to install a more recent version of boost on your system.

From the boost version history page (emphasis mine):

Version 1.75.0
December 11th, 2020 19:50 GMT

New Libraries: JSON, LEAF, PFR. Updated Libraries: Asio, Atomic, Beast, Container, Endian, Filesystem, GIL, Histogram, Interprocess, Intrusive, Log, Move, Mp11, Optional, Outcome, Polygon, Preprocessor, Rational, Signal2, System, uBLAS, VMD, Wave.



Answered By - fabian
Answer Checked By - Senaida (WPSolving Volunteer)