1

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

Link: 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.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153

1 Answers1

4

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.

fabian
  • 80,457
  • 12
  • 86
  • 114
  • Yes, I compiled boost 1.75 and installed. Still having this issue : Scanning dependencies of target test [ 75%] Building CXX object CMakeFiles/test.dir/main.cc.o make[2]: *** No rule to make target '/usr/lib/libboost_json.a', needed by 'test'. Stop. make[1]: *** [CMakeFiles/Makefile2:96: CMakeFiles/test.dir/all] Error 2 make: *** [Makefile:84: all] Error 2 Accepting answer, but this is not resolved yet. Is it a problem with my cmake ? – Vineet Dwivedi Jun 04 '22 at 17:46
  • Another step I had to was to delete all boost-1.71 cmake available under the path /usr/lib/x86_64-linux-gnu/cmake -- If not done, cmake keeps looking for previous version of cmake i.e 1.71 in my case. – Vineet Dwivedi Jun 04 '22 at 17:59
  • 1
    I was able to resolve the problem by reinstalling boost 1.75 without giving any prefix -- chose to install all libraries, remove all cmake files from /usr/lib/cmake and /usr/lib/x86_64-linux-gnu/cmake path. Consider this resolved. This thread can be closed now. – Vineet Dwivedi Jun 04 '22 at 18:34
  • 1
    @VineetDwivedi You should be able to specify the path to look for boost via `Boost_ROOT` variable as mentioned in the ["config mode search procedure" section of the `find_package` doc](https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure) (look for `_ROOT`) – fabian Jun 05 '22 at 08:54