gettingstarted.html revision 4139
4139N/A<h1>Getting Started<a class="headerlink" href="#getting-started" title="Permalink to this headline">¶</a></h1>
4139N/A<h2>Compiling and Installing Jansson<a class="headerlink" href="#compiling-and-installing-jansson" title="Permalink to this headline">¶</a></h2>
4139N/A<a class="reference external" href="http://www.digip.org/jansson/releases/">http://www.digip.org/jansson/releases/</a>.</p>
4139N/A<h3>Unix-like systems (including MinGW)<a class="headerlink" href="#unix-like-systems-including-mingw" title="Permalink to this headline">¶</a></h3>
4139N/Abunzip2 -c jansson-2.7.tar.bz2 | tar xf -
4139N/A<p>The source uses GNU Autotools (<a class="reference external" href="http://www.gnu.org/software/autoconf/">autoconf</a>, <a class="reference external" href="http://www.gnu.org/software/automake/">automake</a>, <a class="reference external" href="http://www.gnu.org/software/libtool/">libtool</a>), so
4139N/A<div class="highlight-c"><div class="highlight"><pre><span class="p">.</span><span class="o">/</span><span class="n">configure</span>
4139N/A<p>To change the destination directory (<tt class="docutils literal"><span class="pre">/usr/local</span></tt> by default), use
4139N/Athe <tt class="docutils literal"><span class="pre">--prefix=DIR</span></tt> argument to <tt class="docutils literal"><span class="pre">/configure</span></tt>. See <tt class="docutils literal"><span class="pre">/configure</span>
4139N/A<span class="pre">--help</span></tt> for the list of all possible installation options. (There are
4139N/A<p>The command <tt class="docutils literal"><span class="pre">make</span> <span class="pre">check</span></tt> runs the test suite distributed with
4139N/Acontrol system), there’s no <tt class="docutils literal"><span class="pre">/configure</span></tt> script as it’s not kept in
4139N/A<div class="highlight-c"><div class="highlight"><pre><span class="n">autoreconf</span> <span class="o">-</span><span class="n">vi</span>
4139N/A<p>This command creates the <tt class="docutils literal"><span class="pre">/configure</span></tt> script, which can then be
4139N/A<span id="build-cmake"></span><h3>CMake (various platforms, including Windows)<a class="headerlink" href="#cmake-various-platforms-including-windows" title="Permalink to this headline">¶</a></h3>
4139N/A<p>Jansson can be built using <a class="reference external" href="http://www.cmake.org">CMake</a>. Create a build directory for an
4139N/Aout-of-tree build, change to that directory, and run <tt class="docutils literal"><span class="pre">cmake</span></tt> (or <tt class="docutils literal"><span class="pre">ccmake</span></tt>,
4139N/A<tt class="docutils literal"><span class="pre">cmake-gui</span></tt>, or similar) to configure the project.</p>
4139N/A<p class="last">In the below examples <tt class="docutils literal"><span class="pre">..</span></tt> is used as an argument for <tt class="docutils literal"><span class="pre">cmake</span></tt>.
4139N/AIn the example it is assumed you’ve created a sub-directory <tt class="docutils literal"><span class="pre">build</span></tt>
4139N/A<span id="build-cmake-unix"></span><h4>Unix (Make files)<a class="headerlink" href="#unix-make-files" title="Permalink to this headline">¶</a></h4>
4139N/Abunzip2 -c jansson-2.7.tar.bz2 | tar xf -
4139N/Acmake .. # or <tt class="xref c c-func docutils literal"><span class="pre">ccmake</span> <span class="pre">..()</span></tt> for a GUI.
4139N/A<h4>Windows (Visual Studio)<a class="headerlink" href="#windows-visual-studio" title="Permalink to this headline">¶</a></h4>
4139N/ATo run the unit tests build the <tt class="docutils literal"><span class="pre">RUN_TESTS</span></tt> project.</p>
4139N/A<p>If you prefer a GUI the <tt class="docutils literal"><span class="pre">cmake</span></tt> line in the above example can
4139N/A<div class="highlight-c"><div class="highlight"><pre><span class="n">cmake</span><span class="o">-</span><span class="n">gui</span> <span class="p">..</span>
4139N/A<p>To list available <a class="reference external" href="http://www.cmake.org">CMake</a> settings (and what they are currently set to)
4139N/A<div class="highlight-c"><div class="highlight"><pre><span class="n">cmake</span> <span class="o">-</span><span class="n">LH</span> <span class="p">..</span>
4139N/A<h4>Mac OSX (Xcode)<a class="headerlink" href="#mac-osx-xcode" title="Permalink to this headline">¶</a></h4>
4139N/A<span class="n">cmake</span> <span class="o">-</span><span class="n">G</span> <span class="s">"Xcode"</span> <span class="p">..</span>
4139N/A<h4>Additional CMake settings<a class="headerlink" href="#additional-cmake-settings" title="Permalink to this headline">¶</a></h4>
4139N/A<h5>Shared library<a class="headerlink" href="#shared-library" title="Permalink to this headline">¶</a></h5>
4139N/A<p>By default the <a class="reference external" href="http://www.cmake.org">CMake</a> project will generate build files for building the
4139N/A<span class="n">cmake</span> <span class="o">-</span><span class="n">DJANSSON_BUILD_SHARED_LIBS</span><span class="o">=</span><span class="mi">1</span> <span class="p">..</span>
4139N/A<h5>Changing install directory (same as autoconf –prefix)<a class="headerlink" href="#changing-install-directory-same-as-autoconf-prefix" title="Permalink to this headline">¶</a></h5>
4139N/A<p>Just as with the <a class="reference external" href="http://www.gnu.org/software/autoconf/">autoconf</a> project you can change the destination directory
4139N/Afor <tt class="docutils literal"><span class="pre">make</span> <span class="pre">install</span></tt>. The equivalent for autoconfs <tt class="docutils literal"><span class="pre">/configure</span> <span class="pre">--prefix</span></tt>
4139N/A<span class="n">cmake</span> <span class="o">-</span><span class="n">DCMAKE_INSTALL_PREFIX</span><span class="o">:</span><span class="n">PATH</span><span class="o">=/</span><span class="n">some</span><span class="o">/</span><span class="n">other</span><span class="o">/</span><span class="n">path</span> <span class="p">..</span>
4139N/A<h3>Android<a class="headerlink" href="#android" title="Permalink to this headline">¶</a></h3>
4139N/A<tt class="docutils literal"><span class="pre">android</span></tt> directory in the source distribution.</p>
4139N/A<h3>Other Systems<a class="headerlink" href="#other-systems" title="Permalink to this headline">¶</a></h3>
4139N/A<p>On non Unix-like systems, you may be unable to run the <tt class="docutils literal"><span class="pre">/configure</span></tt>
4139N/Abe found in the <tt class="docutils literal"><span class="pre">src/</span></tt> directory.</p>
4139N/A<li>Create <tt class="docutils literal"><span class="pre">jansson_config.h</span></tt> (which has some platform-specific
4139N/Aparameters that are normally filled in by the <tt class="docutils literal"><span class="pre">/configure</span></tt>
4139N/Ascript). Edit <tt class="docutils literal"><span class="pre">jansson_config.h.in</span></tt>, replacing all <tt class="docutils literal"><span class="pre">@variable@</span></tt>
4139N/Aplaceholders, and rename the file to <tt class="docutils literal"><span class="pre">jansson_config.h</span></tt>.</li>
4139N/A<li>Make <tt class="docutils literal"><span class="pre">jansson.h</span></tt> and <tt class="docutils literal"><span class="pre">jansson_config.h</span></tt> available to the
4139N/A<li>Compile all the <tt class="docutils literal"><span class="pre">.c</span></tt> files (in the <tt class="docutils literal"><span class="pre">src/</span></tt> directory) into a
4139N/A<h3>Building the Documentation<a class="headerlink" href="#building-the-documentation" title="Permalink to this headline">¶</a></h3>
4139N/A<p>Documentation is in the <tt class="docutils literal"><span class="pre">doc/</span></tt> subdirectory. It’s written in
4139N/A<a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> with <a class="reference external" href="http://sphinx.pocoo.org/">Sphinx</a> annotations. To generate the HTML
4139N/A<div class="highlight-c"><div class="highlight"><pre><span class="n">make</span> <span class="n">html</span>
4139N/A<p>and point your browser to <tt class="docutils literal"><span class="pre">doc/_build/html/index.html</span></tt>. <a class="reference external" href="http://sphinx.pocoo.org/">Sphinx</a> 1.0
4139N/A<h2>Compiling Programs that Use Jansson<a class="headerlink" href="#compiling-programs-that-use-jansson" title="Permalink to this headline">¶</a></h2>
4139N/A<p>Jansson involves one C header file, <tt class="file docutils literal"><span class="pre">jansson.h</span></tt>, so it’s enough
4139N/A<div class="highlight-c"><div class="highlight"><pre><span class="cp">#include <jansson.h></span>
4139N/A<p>There’s also just one library to link with, <tt class="docutils literal"><span class="pre">libjansson</span></tt>. Compile and
4139N/A<div class="highlight-c"><div class="highlight"><pre><span class="n">cc</span> <span class="o">-</span><span class="n">I /usr/include/jansson</span> <span class="o">-</span><span class="n">o</span> <span class="n">prog</span> <span class="n">prog</span><span class="p">.</span><span class="n">c</span> <span class="o">-</span><span class="n">ljansson</span>
4139N/A<p>Starting from version 1.2, there’s also support for <a class="reference external" href="http://pkg-config.freedesktop.org/">pkg-config</a>:</p>
4139N/A<div class="highlight-c"><div class="highlight"><pre>cc -o prog prog.c `pkg-config --cflags --libs jansson`
4139N/A<li><a class="reference internal" href="#compiling-and-installing-jansson">Compiling and Installing Jansson</a><ul>
4139N/A<li><a class="reference internal" href="#unix-like-systems-including-mingw">Unix-like systems (including MinGW)</a></li>
4139N/A<li><a class="reference internal" href="#cmake-various-platforms-including-windows">CMake (various platforms, including Windows)</a><ul>
4139N/A<li><a class="reference internal" href="#windows-visual-studio">Windows (Visual Studio)</a></li>
4139N/A<li><a class="reference internal" href="#additional-cmake-settings">Additional CMake settings</a><ul>
4139N/A<li><a class="reference internal" href="#changing-install-directory-same-as-autoconf-prefix">Changing install directory (same as autoconf –prefix)</a></li>
4139N/A<li><a class="reference internal" href="#building-the-documentation">Building the Documentation</a></li>