11815889af306d5cdd8b1bfddf60e3708d6fc003
[jansson.git] / doc / gettingstarted.rst
1 ***************
2 Getting Started
3 ***************
4
5 .. highlight:: c
6
7 Compiling and Installing Jansson
8 ================================
9
10 This chapter explains how to compile and install the library itself.
11
12
13 Compiling and Installing from a Source Tarball
14 ----------------------------------------------
15
16 Unpack the source tarball and change to the source directory:
17
18 .. parsed-literal::
19
20     bunzip2 -c jansson-|release|.tar.bz2 | tar xf -
21     cd jansson-|release|
22
23 The source uses GNU Autotools (autoconf_, automake_, libtool_), so
24 compiling and installing is extremely simple::
25
26     ./configure
27     make
28     make check
29     make install
30
31 To change the destination directory (``/usr/local`` by default), use
32 the ``--prefix=DIR`` argument to ``./configure``. See ``./configure
33 --help`` for the list of all possible installation options. (There are
34 no options to customize the resulting Jansson binary.)
35
36 The command ``make check`` runs the test suite distributed with
37 Jansson. This step is not strictly necessary, but it may find possible
38 problems that Jansson has on your platform. If any problems are found,
39 please report them.
40
41 .. _autoconf: http://www.gnu.org/software/autoconf/
42 .. _automake: http://www.gnu.org/software/automake/
43 .. _libtool: http://www.gnu.org/software/libtool/
44
45
46 Compiling and Installing from Git
47 ---------------------------------
48
49 If you obtained the source from a Git repository (or any other source
50 control system), there's no ``./configure`` script as it's not kept in
51 version control. To create the script, Autotools needs to be
52 bootstrapped. There are many ways to do this, but the easiest one is
53 to use ``autoreconf``::
54
55     autoreconf -vi
56
57 This command creates the ``./configure`` script, which can then be
58 used as described in the previous section.
59
60
61 Installing Prebuilt Binary Packages
62 -----------------------------------
63
64 Binary ``.deb`` packages for Ubuntu are available in the `Jansson
65 PPA`_ at Launchpad_. Follow the instructions in the PPA ("Read about
66 installing" link) to take the PPA into use. Then install the -dev
67 package::
68
69   apt-get install libjansson-dev
70
71 .. _Jansson PPA: http://launchpad.net/~petri/+archive/ppa
72 .. _Launchpad: http://launchpad.net/
73
74
75
76 Compiling Programs Using Jansson
77 ================================
78
79 Jansson involves one C header file, :file:`jansson.h`, so it's enough
80 to put the line
81
82 ::
83
84     #include <jansson.h>
85
86 in the beginning of every source file that uses Jansson.
87
88 There's also just one library to link with, ``libjansson``. Compile and
89 link the program as follows::
90
91     cc -o prog prog.c -ljansson