views:

373

answers:

3

I'm a new-ish C++ programmer, and I'm doing my first program on my own using C++. I decided I would like to use JSON to store some of the data I'm going to be using, and I've found a library to handle JSON, JsonCpp.

I've installed the library using my Linux system's package manager, and in my C++ code, I've used in my source code file

#include <json>

and compiled it using g++ and it's -ljson and -L/usr/lib options (libjson.so is located in /usr/lib).

However, the first usage of Json::Value, an object provided by the library, gives a compilation error of "Json has not declared". I'm sure my mistake is something simple, so could someone explain what I'm doing wrong? None of the books I had mention how to use shared libraries, so I've had to google to find this much.

EDIT: g++ with the -E option gives this error:

json: no such file or directory.

A: 

Did you also tell g++ where to find the header files via -I - this would be my guess at the problem.

Petriborg
Then he'd get an error on the #include.
bmargulies
A: 

That error pretty nearly certainly implies that you do not have the #include in the actual source file that gets the error.

use

 g++ -E [whatever other options]

to see the cpp output would be one way to check and see what you've actually included.

It might help if you actually paste the error message; your comment suggests an error on the #include, but your question suggests something else.

bmargulies
g++ -E gives json: No such file or directory
Not Joe Bloggs
Did you use all the same options with -E that your used to get your error? Particularly -I options?
bmargulies
+2  A: 

I checked the file list of JsonCPP:

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 the headers are installed in /usr/include. If they're installed somewhere else, mention this path with -I

g++ -I/my/lib/include -L/my/lib/lib -lmylib mysource.cpp
Dmitry Yudakov