2

I'm trying to use libjson within a C++ project and the docs tell me to just "add libjson's source to your project, comment JSON_LIBRARY in the JSONOptions.h file and any C++ compiler should compile it."

Being quite new to C++ and all that, how exactly am I supposed to do that (not using any IDE)? Should I just #include the libjson.h file and that's it? Shouldn't I reference libjson somehow in my call to g++ when compiling my project?

thx in advance

1
  • The text about including libjson in your project seems to be if you want to include the actual libjson source files inside your own project. If you just want to use the library then include whatever header files you need, and link with it as a usual library. Commented Aug 7, 2012 at 9:32

3 Answers 3

3

If you go into the libjson library folder, you will see a makefile. Navigate to that directory in a terminal and type:

make

then

make install

Then, in your code

#include <libjson.h>

or, depending on your include path:

#include <libjson/libjson.h>

That should be all that you need to do.

If you need additional help, you can post in the help forum at sourceforge (I am the author of libjson)

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

Comments

2

You have to:

One,

#include <libjson.h>

in order to get access to the functions and data types the library offers, then

Two, link against the libjsonz library:

g++ -o myprogram myprogram.c -ljson

(the -ljson flag has to come last or you'll get a linker error with never versions of GCC.)

EDIT: if you need to build the library, you typically have a configure script or a Makefile. See how to use them.

2 Comments

ok, but what configuration do I need in order to actually get the library itself? (I'm guessing setting SHARED=1 and building it with the libjson-makefile?)
How do we get -ljson on debian though? I've tried to install libjson-glib-dev, libjson-c-dev, libjson-c3, libjsoncpp-dev. I can't get -ljson! Where can i get it?
0

if you install json you should find include file at /usr/local/include so

#include <json/json.h>

gcc exasmple.c -ljson

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.