1

Firstly I'm using Rasbian on my RPi B running of a 80GB usb hard disk. My basic boot strap for any of my software is:

sudo apt-get install subversion
sudo apt-get install g++
sudo apt-get install libgtk2.0-dev
svn co https://svn.code.sf.net/p/lgi/code/trunk Lgi/trunk
cd Lgi/trunk
ln -s Makefile.linux makefile
make

This works great on ubuntu. To build and run a simple app that uses the lib:

cd LgiIde
ln -s Makefile.linux makefile
make
./lgiide

Which then proceeds to crash fairly early on inside GTK2, overwriting the stack. This is fairly mature code that has been running well on ubuntu for ages. Having a look at the crash in gdb didn't yield anything obviously wrong in my code. And there is no valgrind to run things against. So I downloaded the GTK2 source and built it with debug turned on. Installed it to the default /usr/local position. Now I tried to rebuild LgiIde so that it picks up the new GTK2 build but it links against the old library. Here's where it gets weird, the makefile specifies the GTK headers and libs using pkg-config:

pi@rpi ~/Code/Lgi/trunk $ pkg-config --cflags gtk+-2.0
-pthread -I/usr/local/include/gtk-2.0 -I/usr/local/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/harfbuzz  

pi@rpi ~/Code/Lgi/trunk $ pkg-config --libs gtk+-2.0
-L/usr/local/lib -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lglib-2.0 

So that's clearing picking up the /usr/local build, not the default release mode GTK2 installed by apt-get. However my binary still links against the apt-get libraries:

pi@rpi ~/Code/Lgi/trunk $ ldd Debug/liblgid.so | grep gtk
libgtk-x11-2.0.so.0 => /usr/lib/arm-linux-gnueabihf/libgtk-x11-2.0.so.0 (0xb6814000)

For reference:

pi@rpi ~/Code/Lgi/trunk $ find /usr -iname "*gtk-x11-2.0*"
/usr/local/lib/libgtk-x11-2.0.so.0.2400.25
/usr/local/lib/libgtk-x11-2.0.so
/usr/local/lib/libgtk-x11-2.0.la
/usr/local/lib/libgtk-x11-2.0.so.0
/usr/lib/arm-linux-gnueabihf/libgtk-x11-2.0.so
/usr/lib/arm-linux-gnueabihf/libgtk-x11-2.0.so.0.2400.10
/usr/lib/arm-linux-gnueabihf/libgtk-x11-2.0.so.0
/usr/lib/arm-linux-gnueabihf/libgtk-x11-2.0.a

I'm running out of ideas here... how do I get it to link to the new GTK2?

  • 1
    BTW, debugging symbols are generally available in add on packages with a -dbg suffix. If you apt-cache search gtk | grep debug you should find stuff. gdb sometimes spits a note out about this. – goldilocks Jan 11 '15 at 15:39
1

The folks behind raspbian did a peculiar thing. Here's the default contents of /etc/ld.so.conf.d:

00-vmcs.conf
arm-linux-gnueabihf.conf  
libc.conf

When you run ldconfig after adding a new library to the system (you did do that, right?), links are cached by searching directories with the following precedence:

  1. Anything specified on the command line.
  2. List of things in /etc/ld.so.conf.
  3. Lists of thing in files in any directories included from /etc/ld.so.conf, which normally (including on raspbian) would be the files in /etc/ld.so.conf.d (e.g, the ones listed above). These are processed in lexicographical order.
  4. /lib and /usr/lib.

On Debian (derived) systems, the file /etc/ld.so.conf.d/libc.conf references /usr/local/lib. What this means on a normal such system (e.g., desktop ubuntu) is that /usr/local/lib takes precedence over the hardcoded paths in point #4.

But the base libraries on raspbian are arranged a little oddly -- e.g., libc is actually in a non-standard location, /lib/arm-linux-gnueabihf. This and a parallel directory in /usr/lib are listed in the file arm-linux-gnueabihf.conf.1 Consequently, since that file sorts lexicographically before libc.conf, these standard libraries take precedence over anything in /usr/local/lib.

Not a very nice choice to make, since this inverts the common practice precedence on Debian. Anyway, to fix that (as root):

cd /etc/ld.so.conf.d
mv arm-linux-gnueabihf.conf 20-arm-linux-gnueabihf.conf 
mv libc.conf 10-libc.conf

That swaps the sort order of the files. Now run sudo ldconfig and check your executable w/ ldd again, you should get the link to /usr/local/lib.


1. Why that was necessary I don't know -- pidora does not do this, all the libraries are arranged normally.

  • 1
    That tweak works really nicely. Thanks for answering so completely. I didn't know about the ld.so.conf.d thing at all. After changing the order my app runs fine with the GTK2 that I built myself. No crash. So I don't know what the deal is with the apt-get binary. – fret Jan 12 '15 at 4:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.