Installing (compiling) jshon with libjansson on an old Linux (SLES 10)

Written by - 0 comments

Published on - Listed in Shell Linux

Installing packages on old and end of life releases is sometimes very time intensive. Repositories might be gone, packages out of date, dependencies defect, etc. In this particular case the jshon command needed to be installed on an old SLES 10 machine. However: Even if some repositories still would work, a jshon rpm for SLES10 does not exist. Time to build it from source.

Download the source and dependency (jansson)

The latest jshon.tar.gz can be downloaded from the project site. To be able to build jshon, a dependency (jansson library) must be available. Therefore the sources of both packages need to be downloaded and unpacked:

sles10:~ # wget
sles10:~ # wget
sles10:~ # tar -xzf jshon.tar.gz; tar -xzf jansson-2.12.tar.gz

Compiling jansson

Before jshon can be compiled, it's dependency jansson must first be built on this system. Compiling jansson is straightforward and as long as all compiling tools (gcc, libtool, make, m4, etc) are available, this should work without any error:

sles10:~ # cd jansson-2.12
sles10:~ # ./configure && make

A successful compile will create the needed header files (jansson.h and jansson_config.h) and the library (libjansson) itself. The header files are located in the src sub directory and can now be copied into the unpacked jshon directory:

sles10:~/jansson-2.12 # cp src/jansson.h ../jshon-20120914/
sles10:~/jansson-2.12 # cp src/jansson_config.h ../jshon-20120914/

The libjansson library, including symlinks, can be found in the src/.libs sub directory and should be copied into the system's library path (as defined with ldconfig, usually in /usr/lib/):

sles10:~/jansson-2.12 # ls -ltr src/.libs
total 576
-rw-r--r-- 1 root root   6592 Feb 28 08:31 utf.o
-rw-r--r-- 1 root root  23124 Feb 28 08:36 dump.o
-rw-r--r-- 1 root root   7228 Feb 28 08:36 memory.o
-rw-r--r-- 1 root root  37192 Feb 28 08:36 load.o
-rw-r--r-- 1 root root   6472 Feb 28 08:36 hashtable_seed.o
-rw-r--r-- 1 root root  21084 Feb 28 08:36 hashtable.o
-rw-r--r-- 1 root root   7656 Feb 28 08:36 error.o
-rw-r--r-- 1 root root  47160 Feb 28 08:36 value.o
-rw-r--r-- 1 root root   7944 Feb 28 08:36 strconv.o
-rw-r--r-- 1 root root   7708 Feb 28 08:36 strbuffer.o
-rw-r--r-- 1 root root  35296 Feb 28 08:36 pack_unpack.o
-rw-r--r-- 1 root root   1302 Feb 28 08:36 libjansson.ver
-rwxr-xr-x 1 root root 149076 Feb 28 08:36
lrwxrwxrwx 1 root root     20 Feb 28 08:36 ->
lrwxrwxrwx 1 root root     20 Feb 28 08:36 ->
-rw-r--r-- 1 root root    949 Feb 28 08:36 libjansson.lai
lrwxrwxrwx 1 root root     16 Feb 28 08:36 -> ../
-rw-r--r-- 1 root root   1206 Feb 28 08:36 libjansson.exp
-rw-r--r-- 1 root root 197868 Feb 28 08:36 libjansson.a

sles10:~/jansson-2.12 # cp -p src/.libs/* /usr/lib/

Alternative: Add the path (~/jansson-2.12/src/.libs) to ldconfig.

Compiling and installing jshon

Now that jansson is ready on the system, let's continue with jshon. In the unpacked jshon directory there should now be the following files:

sles10:~/jansson-2.12 # cd ../jshon-20120914

sles10:~/jshon-20120914 # ll
total 60
-rw-r--r-- 1 leoevent users   636 Oct  4  2012 Makefile
-rw-r--r-- 1 root     root  12726 Feb 28 08:37 jansson.h
-rw-r--r-- 1 root     root   1627 Feb 28 08:50 jansson_config.h
-rw-r--r-- 1 leoevent users  6672 Oct  4  2012 jshon.1
-rw-r--r-- 1 leoevent users 25545 Feb 28 08:43 jshon.c

jshon.c is the actual jshon command as C source. It includes the jansson header dependency:

sles10:~/jshon-20120914 # grep jansson jshon.c
#include <jansson.h>
    build with gcc -o jshon jshon.c -ljansson
// deal with API incompatibility between jansson 1.x and 2.x

So-called C header files can be included in two ways:

  1. #include <jansson.h>: Using the file name inside "less than" and "greater than" brackets means that the file (jansson.h) should be searched within the system's header files location (usually /usr/include).
  2. #include "jansson.h": Without using the brackets but using double-quotes instead will search for the file (jansson.h) in the same directory/path as the C file.

Using sed, the inclusion method can be changed:

sles10:~/jshon-20120914 # sed -i '/include/s/<jansson.h>/"jansson.h"/' jshon.c

The c file will now look for the jansson header file in the same path and make can be executed:

sles10:~/jshon-20120914 # make
cc   jshon.o  -ljansson -o jshon

This finally results in a jshon binary:

sles10:~/jshon-20120914 # file jshon
jshon: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.4, dynamically linked (uses shared libs), not stripped

The binary can now be executed locally or placed into a location used by the $PATH shell variable:

sles10:~/jshon-20120914 # cp jshon /usr/bin/

And voilĂ : jshon can be executed from anywhere in the system:

sles10:~ # jshon --help
jshon --help
jshon: invalid option -- -
Valid: -[P|S|Q|V|C|I] [-F path] -[t|l|k|u|p|a] -[s|n] value -[e|i|d] index

Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.

RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Database   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Office   PGSQL   PHP   Perl   Personal   PostgreSQL   Postgres   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder