How do I use a shared library (in this case JsonCpp) in my C ++ program on Linux?
I am a C ++ programmer and I am making my first program myself using C ++. I decided to use JSON to store some of the data that I will be using and found a library to handle JSON, JsonCpp .
I installed the library using my Linux system package manager and in my C ++ code I used in my source code the file
#include <json>
and compiled it with g ++ and it has -ljson and -L / usr / lib options (libjson.so is in /usr/lib
).
However, the first use of Json :: Value, an object provided by the library, gives a "Json not declared" compilation error. I'm pretty sure my mistake is something simple, so can someone please explain what I am doing wrong? None of the books I mentioned in how to use shared libraries, so I had to google a lot.
EDIT: g ++ with the -E option gives this error:
json: No such file or directory.
a source to share
I checked the list of JsonCPP files:
include/json/autolink.h [code]
include/json/config.h [code]
include/json/features.h [code]
include/json/forwards.h [code]
include/json/json.h [code]
include/json/reader.h [code]
include/json/value.h [code]
include/json/writer.h [code]
Try #include <json/json.h>
if headers are set to /usr/include
. If they are installed somewhere else, specify that path with-I
g++ -I/my/lib/include -L/my/lib/lib -lmylib mysource.cpp
a source to share
This error almost certainly implies that you don't have #include
in the actual source file that is receiving the error.
use
g++ -E [whatever other options]
to see the cpp output would be one way to check and see what you actually included.
It might help if you actually insert the error message; your comment suggests an error in #include, but your question suggests something else.
a source to share