10

Am new to cpp but as per project requirements i need to consume rest api and parse the response. Am able to call api & capture the response but not able to parse it using JSONCPP library.

These are the steps i followed to parse json:

  1. Used this command to install libjsoncpp in ubuntu sudo apt-get install libjsoncpp-dev
  2. Downloaded json source files and copied json header files into project folder
  3. Compiling cpp using this command gcc -o test.out test.cpp -ljson

it is always giving

fatal error: json/json.h: No such file or directory
 #include <json/json.h>
                       ^
compilation terminated.

Didn't find any solution since 2 days. Tried this also. Can any one tell me where i am going wrong...

2
  • What does "Downloaded json source files and copied json header files into project folder" mean exactly? Commented Apr 26, 2016 at 9:57
  • I was facing same issue as this on macos. For me converting #include <json/json.h> to #include "json/json.h" did the trick. Commented Jun 8, 2023 at 7:14

2 Answers 2

11

Since you're on Ubuntu I went to their package website and found the file list for the package you installed: http://packages.ubuntu.com/trusty/amd64/libjsoncpp-dev/filelist

The first few files make the problem clear:

/usr/include/jsoncpp/json/autolink.h
/usr/include/jsoncpp/json/config.h
/usr/include/jsoncpp/json/features.h
/usr/include/jsoncpp/json/forwards.h
/usr/include/jsoncpp/json/json.h

Since compilers usually look in /usr/include, you need to provide the rest of the path, i.e.:

#include <jsoncpp/json/json.h>

You could also have found this file on your running system after installing the package by running this command:

locate json.h

Or using the dpkg command after installing the package.

And when you link your program, you need to say -ljsoncpp, not -ljson.

Sign up to request clarification or add additional context in comments.

11 Comments

I'm confused, what does he have to change with the #include statement
@AviParshan Instead of #include <json/json.h>, it's #include <jsoncpp/json/json.h>.
Hello, I am having the same issue on mac. Although I installed the jsoncpp lib and cmake command runs fine, but make command complains about "jsoncpp/json/json.h" not found But my IDE shows the the file when I change the include into json/json.hand doesn't give any error but make command still says "json/json.h" not found have any idea?
@AkilDemir: Search your disk for json.h. What's the full path to it?
Right, you need to add /usr/local/include to your include path.
|
6

another solution:

sudo apt-get install libjsoncpp-dev 
sudo ln -s /usr/include/jsoncpp/json/ /usr/include/json

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.