yajl-tcl

What: yajl-tcl
Where: http://flightaware.github.com/yajl-tcl/
Github project: https://github.com/flightaware/yajl-tcl
Description: TCL-Binding for the yajl library.
yajl (yet another json library) may create and parse JSON strings.
Author: Karl Lehenbauer
Current version: 1.6.1 released 21 Jun 2016
Download: https://github.com/flightaware/yajl-tcl/v1.6.1.tar.gz
Min libyajl version: 1.0.8 (HaO supposes)

Compilation

HaO These are my test candidate experiences. I hope they may serve someone. Feel free to edit and clean-up any stupidity.

  compile yajl-tcl 1.2 on SuSE-Linux

HaO 2012-07-10 Here are the steps (and eventual pitfalls) to build the yajltcl package on SuSE-Linux 11.4 32 bit.

Yajl Header files

  • The SuSE standard package libyajl-devel contains the header files for version 2 of the library. Those are not suitable. Here is the corresponding compile error:
./generic/yajltcl.h:25:5: error: expected specifier-qualifier-list before ‘yajl_gen_config’
  • Take libyajl1 source folder src/api contents [L1 ] and copy it to /usr/local/include/yajl.
  • (untested) there is a package libyajl1-devel in the packman repository. This may also work.

Yajl Library files

  • Use YaST (package manager) to install the standard package libyajl1. This installs the library in the file /usr/lib/libyajl.so.1.
  • Create a symbolic link to use version 1 library as default library:
cd /usr/local/lib
ln -s /usr/lib/libyajl.so.1 libyajl.so
  • Here is the link error, if libyajl.so is not available in the library path:
cannot find -lyajl

Compile Yajl-tcl

  • Download and unpack the source archive yajl-tcl-1.2.tar.gz
  • Invoke autoconf as the script configure is missing in the distribution
autoconf
  • Run configure. I use a temporary install location which is available without superuser. There is only a library build and installed. The --exec-prefix is only necessary to avoid a write error for nothing.
./configure --prefix=/home/oehhar/test/yajl-install --exec-prefix=/home/oehhar/test/yajl-install
  • compile
make
  • install
make install

The tcl package is contained in the folder /home/oehhar/test/yajl-tcl-install-lib/yajltcl1.2.


  compile yajl-tcl 1.2 on Cent-OS 6.3 for architecture x86_64

Yajl Library

The package yjal-devel is not suitable, because the contained yajl version 1.0.7 is not sufficient. The following error arises:

./generic/yajltcl.c:550: Error: »yajl_gen_no_buf« not defined

The described symbol is defined since yajl 1.0.8.

Thus, yajl must be build by hand:

  • If you don't have the package cmake:
yum install cmake
  • unpack the archive lloyd-yajl-1.0.2.tar.gz to a user folder. I used /home/admin/test/yajl. I renamed the top folder of the archive lloyd-yajl-<number> to yajl.
  • go to the source folder, create a build folder and invoke cmake and make:
cd /home/admin/test/yajl
mkdir build
cd build
cmake ..
make
  • This will generate the following files in /home/admin/test/yajl/build/yajl-1.0.12/lib:
-rw-rw-r-- libyajl_s.a
lrwxrwxrwx libyajl.so -> libyajl.so.1
lrwxrwxrwx libyajl.so.1 -> libyajl.so.1.0.12
-rwxrwxr-x libyajl.so.1.0.12
  • As I did not find out how to convince cmake to set library target to /usr/local/lib64, I am installing on my own (as root):
cd /usr/local/lib64
cp /home/admin/test/yajl/build/yajl-1.0.12/lib/libyajl.so.1.0.12 .
ln -s libyajl.so.1.0.12 libyajl.so.1
ln -s libyajl.so.1 libyajl.so
  • The last symbolic link is (opposed to SuSE-Linux, see above) not necessary.
  • and finally copy the include files as folder include/yajl to /usr/local/include:
    cd /usr/local/include
    cp -r /home/admin/test/yajl/build/yajl-1.0.12/include/* .

Yajl-tcl library

  • unpack in /home/admin/test/yajl-tcl and change to this folder. Invoke autoconf to generate the configure-script:
cd /home/admin/test/yajl-tcl
autoconf
  • Run configure and compile.
    • The tcl config file tclConfig.sh is located on my system in /usr/local/lib64 which is passed by --with-tcl.
    • The --mandir tries to cure that the used man location is /usr/local/share/man. But anyway, this does not matter as there are no man pages.
./configure --with-tcl=/usr/local/lib64 --mandir=/usr/local/man
make
  • Change to superuser and install
make install
  • This installs the library correctly to /usr/local/lib64 and aborts with the following error due to missing man pages:
/usr/bin/install: Aufruf von stat für „./doc/*.n“ nicht möglich: Datei oder Verzeichnis nicht gefunden
  • This error may be ignored

Apache-Rivet

As apache-rivet does not include the library path /usr/local/lib64, an additional link is helpful:

cd /usr/lib64
ln -s /usr/local/lib64/libyajl.so.1

The library is searched here with the suffix .1. This is different to SuSE-Linux.

  yajl-tcl 1.3

yajl-tcl 1.3

This yajl-tcl supports the current yajl version 2 library. so lets try compilation again:

  compile yajl-tcl 1.3 on SuSE-Linux

HaO 2012-09-07 Here are the steps (and eventual pitfalls) to build the yajltcl package on SuSE-Linux 11.4 32 bit.

Yajl Library files

  • Use YaST (package manager) to install libyajl2 (/usr/lib/libyajl.so.2) and libyajl-devel (/usr/include/yajl)(both package version 2.0.1-35) from the packman repository.

Compile Yajl-tcl

  • Download and unpack the source archive yajl-tcl-1.2.tar.gz
  • Invoke autoconf as the script configure is missing in the distribution
autoconf
  • Run configure. I use a temporary install location which is available without superuser. There is only a library build and installed. Setting --exec-prefix leads to the error unrecognized option. But the configure script outputs, that --exec-prefix defaults to /usr.
./configure --prefix=/home/oehhar/test/yajl-install
  • compile
make
  • install
make install

(as root). The tcl package is contained in the folder /usr/yajltcl1.3 and the folder /home/oehhar/test/yajl-install/include is created with no content.


  compile yajl-tcl 1.3 on Cent-OS 6.3 for architecture x86_64

Yajl Library

Found rpm's only have version 1.0.7. So anyway, build by hand:

  • If you don't have the package cmake:
yum install cmake
  • unpack the archive lloyd-yajl-2.0.1.tar.gz to a user folder. I used /home/admin/test/yajl. I renamed the top folder of the archive lloyd-yajl-<number> to yajl.
  • go to the source folder, create a build folder and invoke cmake and make:
cd /home/admin/test/yajl
mkdir build
cd build
cmake ..
make
  • This will generate the following files in /home/admin/test/yajl/build/yajl-2.0.1/lib:
-rw-rw-r-- libyajl_s.a
lrwxrwxrwx libyajl.so -> libyajl.so.2
lrwxrwxrwx libyajl.so.2 -> libyajl.so.2.0.1
-rwxrwxr-x libyajl.so.2.0.1
  • As I did not find out how to convince cmake to set library target to /usr/local/lib64, I am installing on my own (as root):
cd /usr/local/lib64
cp /home/admin/test/yajl/build/yajl-1.0.12/lib/libyajl.so.2.0.1 .
ln -s libyajl.so.2.0.1 libyajl.so.2
ln -s libyajl.so.2 libyajl.so

yajl-tcl will not compile without the last. If the last points to libyajl.so.1, a final package require yajltcl would output the error:

couldn't load file "/usr/local/lib64/yajltcl1.3/libyajltcl1.3.so": /usr/local/lib64/yajltcl1.3/libyajltcl1.3.so: undefined symbol: yajl_config
  • and finally copy the include files as folder include/yajl to /usr/local/include:
    cd /usr/local/include
    cp -r /home/admin/test/yajl/build/yajl-2.0.1/include/* .

Yajl-tcl library

  • unpack in /home/admin/test/yajl-tcl and change to this folder. Invoke autoconf to generate the configure-script:
cd /home/admin/test/yajl-tcl
autoconf
  • Run configure and compile.
    • The tcl config file tclConfig.sh is located on my system in /usr/local/lib64 which is passed by --with-tcl.
    • The --mandir tries to cure that the used man location is /usr/local/share/man. But anyway, this does not matter as there are no man pages.
./configure --with-tcl=/usr/local/lib64 --mandir=/usr/local/man
make
  • Change to superuser and install
make install
  • This installs the library correctly to /usr/local/lib64

Apache-Rivet

As apache-rivet does not include the library path /usr/local/lib64, an additional link is helpful:

cd /usr/lib64
ln -s /usr/local/lib64/libyajl.so.2

The library is searched here with the suffix .2. This is different to SuSE-Linux.

Usage

  yajltcl objects and namespaces

yajltcl creates its objects as commands in the global namespace:

% namespace eval ns {yajl create y1}
y1
% info commands y1 
y1

Specify a namespace prefix to put the command is a distinct namespace:

% namespace eval ns {yajl create ::ns::y1}
::ns::y1
% info commands y1 
% namespace eval ns {info commands y1}
y1

  What is meant by `state` in the manual

(Complement to [L2 ]) The kept state is the count of open maps and arrays. Here is an example, where two array elements (which are maps) are streamed to stdout (using Rivet) one by one.

Here is the code for the first part:

yajl create y1 -beautify 1
y1 array_open
y1 map_open string "name" string "Duck" string "surname" string "Donald" map_close
puts [y1 get]

This will send:

[
        {
                "name": "Duck",
                "surname": "Donald"
        }

Here is the code for the second and last array element:

y1 map_open string "name" string "Duck" string "surname" string "Daisy" map_close
y1 array_close
puts [y1 get]
y1 reset

which will send:

        ,
        {
                "name": "Duck",
                "surname": "Daisy"
        }
]

You need resetif you want to reuse the y1command for further JSON objects.