How to tutorials, Linux, Linux.Tips

How to install and use JsonCpp library on Ubuntu Linux OS?

1 min read

JsonCpp is a lightweight data-interchange format. It can represent numbers, strings, ordered sequences of values, and collections of name/value pairs.

Step 1: Install using apt-get

You can easily install JsonCpp library on Ubuntu or another flavor of Debian Linux simply by running the following command:
sudo apt-get install libjsoncpp-dev
It will install the compatible JsonCpp library on your system.

Step 2: Example program and compiler flag To compile a C++ program that uses JsonCpp library use the compiler flag:
-ljsoncpp
Create a Json file called profile.json with the following content:

Within the same directory create a profile.cpp file with the following source code:

Compile it:
g++ -o profile profile.cpp -ljsoncpp
Run it:
./profile
That’s it, if you can run the profile program you have successfully configured JsonCpp library.


Leave a Reply