Friday, June 26, 2009

Troubles while installing different versions of GTK on same machine

Well, to start off with my initial days working on GTK, one of the biggest challenge is to install different versions of GTK (2.x series) on the same machine. Initially it was a hell to understand the procedure of installation - compiling, making and then, installing. Errors crop-up almost on each and every step of execution saying that the dependency doesn't exist, linking errors, blah blah...

Instructions required to install a particular version of GTK (2.x) at our preferred location is -
  • Download the required version of GTK from ftp://ftp.gtk.org/pub/gtk/
  • Make sure you either downloaded all the required dependecies, or your system is already updated. All the dependent libraries are available from the same location.
    Note: Suppose, a particular version of GTK requires Pango 1.4 and your system already has Pango 1.10, then don't take your breath easily. This might lead to other problems as well such as, the code is changed between versions and the same function is defined in different libraries. So, to the extent possible, try to get the nearest library version in order to avoid those scrap issues.
  • To organise your various GTK installations better, make a dir to hold all of your GTK libraries - something like /usr/local or /opt. That dir will have all the installed versions - gtk2.4, gtk2.8 etc. For this purpose you would create the corresponding folder.
  • The most important thing to build/compile is - the order in which you build matters. For eg., GTK 2.8 and later versions require Cairo, where as it's previous versions doesn't need Cairo. However, the order in which to build things should be the same.
    Pay attention to tricky part of the installation about using the PKG_CONFIG_PATH environment variable. That's how you let the libraries find the proper versions of their dependencies.
  • The first new thing to note is that GTK+ 2.8 now has a new prerequisite package: cairo. This is an interesting package that is easy to build and install. I first build glib, then cairo, then pango, atk and GTK+. This order is important. Cairo has to be built before pango so pango can create a cairo backend....and ATK sits atop Pango.

    There is a little trick to building a developer version. First create a directory in which all this will be installed:
    mkdir /usr/local/gimp-2.4
    Make sure you have write access to it, of course. Then build glib with
    ./configure --prefix=/usr/local/gimp-2.4
    make
    make install

    Now comes the trick. To make sure you pick up all the right pkgconfig files for each new package you build, you need to do the following:
    export PKG_CONFIG_PATH=/usr/local/gimp-2.4/lib/pkgconfig:$PKG_CONFIG_PATH
    export LD_LIBRARY_PATH=/usr/local/gimp-2.4/lib:$LD_LIBRARY_PATH
    export PATH=/usr/local/gimp-2.4/bin:$PATH

    Then build each of the other packages with the same three steps used for glib.