1# Linux — Building and Debugging GTK 2 3Sometimes installing the debug packages for gtk and glib isn't quite enough. 4(For instance, if the artifacts from -O2 are driving you bonkers in gdb, you 5might want to rebuild with -O0.) 6Here's how to build from source and use your local version without installing 7it. 8 9[TOC] 10 11## 32-bit systems 12 13On Ubuntu, to download and build glib and gtk suitable for debugging: 14 151. If you don't have a gpg key yet, generate one with `gpg --gen-key`. 162. Create file `~/.devscripts` containing `DEBSIGN_KEYID=yourkey`, e.g. 17 `DEBSIGN_KEYID=CC91A262` (See 18 http://www.debian.org/doc/maint-guide/ch-build.en.html) 193. If you're on a 32 bit system, do: 20 21 ```shell 22 #!/bin/sh 23 set -x 24 set -e 25 # Workaround for "E: Build-dependencies for glib2.0 could not be satisfied" 26 # See also https://bugs.launchpad.net/ubuntu/+source/apt/+bug/245068 27 sudo apt-get install libgamin-dev 28 sudo apt-get build-dep glib2.0 gtk+2.0 29 rm -rf ~/mylibs 30 mkdir ~/mylibs 31 cd ~/mylibs 32 apt-get source glib2.0 gtk+2.0 33 cd glib2.0* 34 DEB_BUILD_OPTIONS="nostrip noopt debug" debuild 35 cd ../gtk+2.0* 36 DEB_BUILD_OPTIONS="nostrip noopt debug" debuild 37 ``` 38 39This should take about an hour. If it gets stuck waiting for a zombie, 40you may have to kill its closest parent (the makefile uses subshells, 41and bash seems to get confused). When I did this, it continued successfully. 42 43At the very end, it will prompt you for the passphrase for your gpg key. 44 45Then, to run an app with those libraries, do e.g. 46 47 export LD_LIBRARY_PATH=$HOME/mylibs/gtk+2.0-2.16.1/debian/install/shared/usr/lib:$HOME/mylibs/gtk+2.0-2.20.1/debian/install/shared/usr/lib 48 49gdb ignores that variable, so in the debugger, you would have to do something like 50 51 set solib-search-path $HOME/mylibs/gtk+2.0-2.16.1/debian/install/shared/usr/lib:$HOME/mylibs/gtk+2.0-2.20.1/debian/install/shared/usr/lib 52 53See also http://sources.redhat.com/gdb/current/onlinedocs/gdb_17.html 54 55## 64-bit systems 56 57If you're on a 64 bit system, you can do the above on a 32 58bit system, and copy the result. Or try one of the following: 59 60### Building your own GTK 61 62```shell 63apt-get source glib-2.0 gtk+-2.0 64 65export CFLAGS='-m32 -g' 66export LDFLAGS=-L/usr/lib32 67export LD_LIBRARY_PATH=/work/32/lib 68export PKG_CONFIG_PATH=/work/32/lib/pkgconfig 69 70# glib 71setarch i386 ./configure --prefix=/work/32 --enable-debug=yes 72 73# gtk 74setarch i386 ./configure --prefix=/work/32 --enable-debug=yes --without-libtiff 75``` 76 77### ia32-libs 78 79_Note: Evan tried this and didn't get any debug libs at the end._ 80 81Or you could try this instead: 82 83``` 84#!/bin/sh 85set -x 86set -e 87sudo apt-get build-dep ia32-libs 88rm -rf ~/mylibs 89mkdir ~/mylibs 90cd ~/mylibs 91apt-get source ia32-libs 92cd ia32-libs* 93DEB_BUILD_OPTIONS="nostrip noopt debug" debuild 94``` 95 96By default, this just grabs and unpacks prebuilt libraries; see 97ia32-libs-2.7ubuntu6/fetch-and-build which documents a BUILD variable which 98would force actual building. This would take way longer, since it builds dozens 99of libraries. I haven't tried it yet. 100 101#### Possible Issues 102 103debuild may fail with 104 105``` 106gpg: [stdin]: clearsign failed: secret key not available 107debsign: gpg error occurred! Aborting.... 108``` 109 110if you forget to create `~/.devscripts` with the right contents. 111 112The build may fail with a `FAIL: abicheck.sh` if gold is your system linker. Use 113ld instead. 114