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

DeX3
  • 5,200
  • 6
  • 44
  • 68
  • 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. – Some programmer dude Aug 07 '12 at 09:32

3 Answers3

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)

adairdavid
  • 413
  • 1
  • 7
  • 17
ninja9578
  • 31
  • 1
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.

  • 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?) – DeX3 Aug 07 '12 at 10:05
  • 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? – Owl Aug 05 '21 at 13:57
0

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

#include <json/json.h>

gcc exasmple.c -ljson

sam
  • 1,363
  • 1
  • 20
  • 32