How to include jsoncpp library into project on unix?

2.5k views Asked by At

The library I am trying to include is jsoncpp. I am having serious trouble with this. I used the home-brew install for this library, which is brew install jsoncpp (brew install is unix version of linux sudo-apt get). Normally homebrew installs stuff to my path, so I can just use it. I am going off of this example here.

#include <json/json.h>

Returns an error of 10: fatal error: 'json/value.h' file not found.

I am using cmake because CLion automatically sets it up. Right now it is very basic:

#CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
project(Read_JSON)

set(CMAKE_CXX_STANDARD 17)

add_executable(Read_JSON main.cpp)

However, for some reason jsoncpp cannot be found. How can I include this library in my project?

3

There are 3 answers

2
Adam Mierzwiak On

You can use in CMake FetchContent capability. Jsoncpp is available via git repository on GitHub

Here is example how I made with googletest: https://github.com/adamvm/hello/blob/master/CMakeLists.txt

You need just substitute proper addresses and names

0
Piotr Henryk Dabrowski On

In Ubuntu (since 18.04) you need to install libjsoncpp-dev[1] package:

sudo apt install libjsoncpp-dev

[1] https://packages.ubuntu.com/search?keywords=libjsoncpp-dev

0
Larisa On

On mac install with command.

brew install osrf/simulation/ignition-fuel-tools2