2

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?

Kevin
  • 16,549
  • 8
  • 60
  • 74
GeneralCode
  • 794
  • 1
  • 11
  • 26
  • What do you mean by "*`jsoncpp` cannot be found*"? Is there a specific error message? CMake error? Compilation error? Linker error? Please add the error log to your question post. – Kevin Jan 31 '20 at 20:02
  • I am going off of this example here. I am getting this when I run: `fatal error: 'json/value.h' file not found` – GeneralCode Jan 31 '20 at 20:05
  • 2
    Try `brew info jsoncpp` to see where it got installed. Then, depending on *where* it was installed, you may need to modify your CMake to include `target_include_directories()` for the jsoncpp include directories, and `target_link_libraries()` so your application can find the jsoncpp libraries. – Kevin Jan 31 '20 at 20:13
  • @squareskittles I ended up figuring out `cmake` builds so I'm no longer dependent on `brew`. Then yes, the `target_include_directories()` and `target_link_libraries()` is used. However, the project I ended up going with just wanted a cmake directory. So this looked like `list(APPEND CMAKE_MODULE_PATH path/to/cmake)` – GeneralCode Feb 01 '20 at 01:30
  • I was facing same issue as this on macos. For me converting `#include ` to `#include "json/json.h"` did the trick. – ishandutta2007 Jun 08 '23 at 07:15

3 Answers3

0

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

Adam Mierzwiak
  • 350
  • 2
  • 6
  • 18
  • 1
    With this method do you need to be connected to the internet every time, only the first time or not at all? – GeneralCode Jan 31 '20 at 20:34
  • Here is two control options that are answer to your question: 'FETCHCONTENT_FULLY_DISCONNECTED' and 'FETCHCONTENT_UPDATES_DISCONNECTED'. All capabilities of this module you can check under [link] https://cmake.org/cmake/help/v3.14/module/FetchContent.html – Adam Mierzwiak Jan 31 '20 at 20:46
0

On mac install with command.

brew install osrf/simulation/ignition-fuel-tools2

Larisa
  • 1
  • 1
0

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