Cross Compiling GTK applications For the Raspberry Pi

In this blog entry I will cover how I was able to cross compile GTK+ 3.0 applications for the Raspberry Pi. I will be assuming that you are running a Debian/Ubuntu flavored Linux distribution on your PC. I was successfully able to cross compile GTK+ 3.0 applications on my PC under both CrashBang Linux 11(Debian based) & Kubuntu 12.04 (Ubuntu based) . The sample code and makefile discussed in this blog entry are available here.

Figure 1. Simple Cross compiled GTK3 application running on the RPi

Figure 1. Simple Cross compiled GTK3 application running on the RPi

I was not able to set up “pkg-config” properly for cross compilation. Instead I’m using a makefile that lists all of the necessary include and library files/directories as well as the library dependency directories. Some of the GTK+ related libraries also required that the libc.so.6 library (and a bunch of others) be placed in a specific static directory (/lib/arm-linux-gnueabihf) . I got around that by creating two soft links; one in the /lib & one in the /usr/lib directories. So this approach may be considered a bit of hack, but it works very well. I’m also using the latest Raspbian OS image on my RPi (2013-07-26 && 2013-05-25 work fine)  and suggest that you do the same.

  • Install the Raspbian OS on an SD Card
  • Plug the SD Card into the Raspberry Pi
  • Connect the Raspberry Pi to the Network and power it
  • SSH into the RPi.
  • Configure the RPi using the raspi-config utility
  • Update all packages on the RPi with the “sudo apt-get update && sudo apt-get upgrade” commands.

The first six steps listed above are covered in detail here.

  • Create a $HOME/rpi directory on your Linux PC. Download the cross-compiling toolchain for the RPi into that directory on your Linux PC and add it’s bin directory  to the PATH variable as instructed here .
  • Now log in remotely onto the RPi via an SSH connection and type: “sudo apt-get install libgtk-3-dev“. This will install the gtk3 libraries and utilities necessary onto the RPi’s SD card.
  • Turn OFF the RPi board, remove the SD card and plug it back into the Linux PC.
  • Copy the /usr and /lib directories from the SD card (root file system partition) into the $HOME/rpi/ on the Linux PC. You can use the graphical file manager or the cp command.
  • Plug the SD card back into the RPi, connect it to the network and turn it on.
  • On the Linux PC, create two soft links in the /lib && /usr/lib directories :
    • sudo ln -s  $HOME/rpi/usr/lib/arm-linux-gnueabihf/ /usr/lib/arm-linux-gnueabihf
    • sudo ln -s $HOME/rpi/lib/arm-linux-gnueabihf/ /lib/arm-linux-gnueabihf
  • Verify that the directory soft links indeed exist with the following two commands:
    • ls -ld /lib/arm-linux-gnueabihf
    • ls -ld /usr/lib/arm-linux-gnueabihf
  • Download and extract the sample code and makefile  available here.
  • The code and makefile are shown below for reference:

gtktest.c

#include <gtk/gtk.h>

gint count = 0;
char buf[5];

void increase(GtkWidget *widget, gpointer label)
{
  count++;

  sprintf(buf, "%d", count);
  gtk_label_set_text(GTK_LABEL(label), buf);
}

void decrease(GtkWidget *widget, gpointer label)
{
  count--;

  sprintf(buf, "%d", count);
  gtk_label_set_text(GTK_LABEL(label), buf);
}

int main(int argc, char** argv) {

  GtkWidget *label;
  GtkWidget *window;
  GtkWidget *frame;
  GtkWidget *plus;
  GtkWidget *minus;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_window_set_default_size(GTK_WINDOW(window), 250, 180);
  gtk_window_set_title(GTK_WINDOW(window), "+-");

  frame = gtk_fixed_new();
  gtk_container_add(GTK_CONTAINER(window), frame);

  plus = gtk_button_new_with_label("+");
  gtk_widget_set_size_request(plus, 80, 35);
  gtk_fixed_put(GTK_FIXED(frame), plus, 50, 20);

  minus = gtk_button_new_with_label("-");
  gtk_widget_set_size_request(minus, 80, 35);
  gtk_fixed_put(GTK_FIXED(frame), minus, 50, 80);

  label = gtk_label_new("0");
  gtk_fixed_put(GTK_FIXED(frame), label, 190, 58); 

  gtk_widget_show_all(window);

  g_signal_connect(window, "destroy",
      G_CALLBACK (gtk_main_quit), NULL);

  g_signal_connect(plus, "clicked", 
      G_CALLBACK(increase), label);

  g_signal_connect(minus, "clicked", 
      G_CALLBACK(decrease), label);

  gtk_main();

  return 0;
}

Makefile

ARM_PREFIX= arm-linux-gnueabihf-
CC   = $(ARM_PREFIX)gcc
SRC += gtktest.c
TARGET = gtktest

LIBRARY += gtk-3 
LIBRARY += gdk-3 
LIBRARY += atk-1.0 
LIBRARY += gio-2.0 
LIBRARY += pangocairo-1.0 
LIBRARY += gdk_pixbuf-2.0 
LIBRARY += cairo-gobject 
LIBRARY += pango-1.0 
LIBRARY += cairo 
LIBRARY += gobject-2.0 
LIBRARY += glib-2.0 

LIBRARYDIR += $(HOME)/rpi/lib/arm-linux-gnueabihf 
LIBRARYDIR += $(HOME)/rpi/usr/lib/arm-linux-gnueabihf 
LIBRARYDIR += $(HOME)/rpi/lib
LIBRARYDIR += $(HOME)/rpi/usr/lib

XLINK_LIBDIR += $(HOME)/rpi/lib/arm-linux-gnueabihf 
XLINK_LIBDIR += $(HOME)/rpi/usr/lib/arm-linux-gnueabihf

INCLUDEDIR += $(HOME)/rpi/usr/include/gtk-3.0 
INCLUDEDIR += $(HOME)/rpi/usr/include/pango-1.0 
INCLUDEDIR += $(HOME)/rpi/usr/include/gio-unix-2.0/ 
INCLUDEDIR += $(HOME)/rpi/usr/include/atk-1.0 
INCLUDEDIR += $(HOME)/rpi/usr/include/cairo 
INCLUDEDIR += $(HOME)/rpi/usr/include/gdk-pixbuf-2.0 
INCLUDEDIR += $(HOME)/rpi/usr/include/freetype2 
INCLUDEDIR += $(HOME)/rpi/usr/include/glib-2.0 
INCLUDEDIR += $(HOME)/rpi/usr/lib/arm-linux-gnueabihf/glib-2.0/include 
INCLUDEDIR += $(HOME)/rpi/usr/include/pixman-1 
INCLUDEDIR += $(HOME)/rpi/usr/include/libpng12

OPT = -O0
DEBUG = -g
WARN= -Wall 
PTHREAD= -pthread

INCDIR  = $(patsubst %,-I%,$(INCLUDEDIR))
LIBDIR  = $(patsubst %,-L%,$(LIBRARYDIR))
LIB    = $(patsubst %,-l%,$(LIBRARY))
XLINKDIR = $(patsubst %,-Xlinker -rpath-link=%,$(XLINK_LIBDIR))

all:
	$(CC) $(OPT) $(DEBUG) $(WARN) $(LIBDIR) $(PTHREAD) $(INCDIR) $(XLINKDIR) $(LIB) $(SRC) -o $(TARGET)

clean:
	rm -rf $(TARGET)
  • In a terminal window on your Linux PC navigate into the “gtktest” directory, “cd ~/gtktest” and run “make“.
  • If everything went well you should end up with a binary compiled for arm called “gtktest”. Type the following command in the terminal “file gtktest“. The output should be: gtktest: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0x72cb5773b65f1dce50358edfebd8be2d44aef967, not stripped.”
  • Copy the arm binary from the Linux PC to the  “home/pi/” directory on the RPi using scp. i.e. Run the following command in a terminal window on your Linux PC “scp $HOME/gtktest/gtktest  pi@10.42.0.73:/home/pi” (replace 10.42.0.73 with the IP address of your RPi). You will be prompted for the a password to connect to the RPi (user pi). It should be “raspberry” unless it was changed.
  • To test the binary on the RPi we will need to start a VNC server on the RPi and connect to it with a VNC client on your Linux PC. Detailed instructions are provided here.
  • Once the VNC session is started, and you can access the RPi’s desktop, open an LXTerminal window and type: “chmod +x gtktest” to make the gtktest binary executable and run it with “./gtktest“.
  • I got the example code from Zetcode’s GTK+ tutorial. I was able to build a few other GTK+ 3.0 examples as well.
  • You can use Eclipse as an IDE if you really want to. Simply move the gtktest directory into your eclipse workspace directory, start eclipse and when creating a new project, choose the “Makefile project with Existing Code” option.
  • Instead of using a VNC server to execute the GUI application remotely on the RPi, you can try X11 forwarding in SSH. I haven’t covered this topic yet but intend to do so in the near future.

 

This entry was posted in Raspberry Pi, Raspberry Pi Cross Development. Bookmark the permalink.

35 Responses to Cross Compiling GTK applications For the Raspberry Pi

  1. Pingback: Cross Compiling GTK applications For the Raspberry Pi « adafruit industries blog

  2. JASON says:

    thank you very much for your tutorial;

    I have finished the last two tutorials, and succeeded, it seems there are some problems in this, and I am confused.

    I followed the steps successfully until the step “In a terminal window on your Linux PC navigate into the “gtktest” directory, “cd ~/gtktest” and run “make“.”

    by the way, the Makefile and gtktest is directly downloaded from the link you give.

    I typed “make” and there are so many errors, mainly about the parameters not been defined as shown below:
    arm-linux-gnueabihf-gcc -O0 -g -Wall -L/home/huang87975716/rpi/lib/arm-linux-gnueabihf -L/home/huang87975716/rpi/usr/lib/arm-linux-gnueabihf -L/home/huang87975716/rpi/lib -L/home/huang87975716/rpi/usr/lib -pthread -I/home/huang87975716/rpi/usr/include/gtk-3.0 -I/home/huang87975716/rpi/usr/include/pango-1.0 -I/home/huang87975716/rpi/usr/include/gio-unix-2.0/ -I/home/huang87975716/rpi/usr/include/atk-1.0 -I/home/huang87975716/rpi/usr/include/cairo -I/home/huang87975716/rpi/usr/include/gdk-pixbuf-2.0 -I/home/huang87975716/rpi/usr/include/freetype2 -I/home/huang87975716/rpi/usr/include/glib-2.0 -I/home/huang87975716/rpi/usr/lib/arm-linux-gnueabihf/glib-2.0/include -I/home/huang87975716/rpi/usr/include/pixman-1 -I/home/huang87975716/rpi/usr/include/libpng12 -Xlinker -rpath-link=/home/huang87975716/rpi/lib/arm-linux-gnueabihf -Xlinker -rpath-link=/home/huang87975716/rpi/usr/lib/arm-linux-gnueabihf -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0 gtktest.c -o gtktest
    /tmp/ccrmziNY.o: In function `increase':
    /home/huang87975716/gtktest/gtktest.c:11: undefined reference to `gtk_label_get_type’
    /home/huang87975716/gtktest/gtktest.c:11: undefined reference to `g_type_check_instance_cast’
    /home/huang87975716/gtktest/gtktest.c:11: undefined reference to `gtk_label_set_text’
    /tmp/ccrmziNY.o: In function `decrease':
    /home/huang87975716/gtktest/gtktest.c:19: undefined reference to `gtk_label_get_type’
    /home/huang87975716/gtktest/gtktest.c:19: undefined reference to `g_type_check_instance_cast’
    /home/huang87975716/gtktest/gtktest.c:19: undefined reference to `gtk_label_set_text’
    /tmp/ccrmziNY.o: In function `main':
    /home/huang87975716/gtktest/gtktest.c:30: undefined reference to `gtk_init’
    /home/huang87975716/gtktest/gtktest.c:32: undefined reference to `gtk_window_new’
    /home/huang87975716/gtktest/gtktest.c:33: undefined reference to `gtk_window_get_type’
    /home/huang87975716/gtktest/gtktest.c:33: undefined reference to `g_type_check_instance_cast’
    /home/huang87975716/gtktest/gtktest.c:33: undefined reference to `gtk_window_set_position’
    /home/huang87975716/gtktest/gtktest.c:34: undefined reference to `gtk_window_get_type’
    /home/huang87975716/gtktest/gtktest.c:34: undefined reference to `g_type_check_instance_cast’
    /home/huang87975716/gtktest/gtktest.c:34: undefined reference to `gtk_window_set_default_size’
    /home/huang87975716/gtktest/gtktest.c:35: undefined reference to `gtk_window_get_type’
    /home/huang87975716/gtktest/gtktest.c:35: undefined reference to `g_type_check_instance_cast’
    /home/huang87975716/gtktest/gtktest.c:35: undefined reference to `gtk_window_set_title’
    /home/huang87975716/gtktest/gtktest.c:37: undefined reference to `gtk_fixed_new’
    /home/huang87975716/gtktest/gtktest.c:38: undefined reference to `gtk_container_get_type’
    /home/huang87975716/gtktest/gtktest.c:38: undefined reference to `g_type_check_instance_cast’
    /home/huang87975716/gtktest/gtktest.c:38: undefined reference to `gtk_container_add’
    /home/huang87975716/gtktest/gtktest.c:40: undefined reference to `gtk_button_new_with_label’
    /home/huang87975716/gtktest/gtktest.c:41: undefined reference to `gtk_widget_set_size_request’
    /home/huang87975716/gtktest/gtktest.c:42: undefined reference to `gtk_fixed_get_type’
    /home/huang87975716/gtktest/gtktest.c:42: undefined reference to `g_type_check_instance_cast’
    /home/huang87975716/gtktest/gtktest.c:42: undefined reference to `gtk_fixed_put’
    /home/huang87975716/gtktest/gtktest.c:44: undefined reference to `gtk_button_new_with_label’
    /home/huang87975716/gtktest/gtktest.c:45: undefined reference to `gtk_widget_set_size_request’
    /home/huang87975716/gtktest/gtktest.c:46: undefined reference to `gtk_fixed_get_type’
    /home/huang87975716/gtktest/gtktest.c:46: undefined reference to `g_type_check_instance_cast’
    /home/huang87975716/gtktest/gtktest.c:46: undefined reference to `gtk_fixed_put’
    /home/huang87975716/gtktest/gtktest.c:48: undefined reference to `gtk_label_new’
    /home/huang87975716/gtktest/gtktest.c:49: undefined reference to `gtk_fixed_get_type’
    /home/huang87975716/gtktest/gtktest.c:49: undefined reference to `g_type_check_instance_cast’
    /home/huang87975716/gtktest/gtktest.c:49: undefined reference to `gtk_fixed_put’
    /home/huang87975716/gtktest/gtktest.c:51: undefined reference to `gtk_widget_show_all’
    /home/huang87975716/gtktest/gtktest.c:53: undefined reference to `gtk_main_quit’
    /home/huang87975716/gtktest/gtktest.c:53: undefined reference to `gtk_main_quit’
    /home/huang87975716/gtktest/gtktest.c:53: undefined reference to `g_signal_connect_data’
    /home/huang87975716/gtktest/gtktest.c:56: undefined reference to `g_signal_connect_data’
    /home/huang87975716/gtktest/gtktest.c:59: undefined reference to `g_signal_connect_data’
    /home/huang87975716/gtktest/gtktest.c:62: undefined reference to `gtk_main’
    collect2: error: ld returned 1 exit status
    make: *** [all] Error 1

    I am a Chinese and new to Linux, I try to figure out the problem but with no result, and I know little about Makefile, so please help me about this.

    and I want to translate your tutorials about raspberry into Chinese to get more Chinese like me to learn from you. I want your permission!

    my gmail is: the.jason.cn@gmail.com, looking forward for your reply.

    Thanks for your reply.

  3. halherta says:

    Jason,
    I’ll retry this and let you know how it went. Which version of Raspbian are you using on the Raspberry Pi (I was using the 05-25-2013 version I believe a newer version has been released)? and which Linux Distro are you using on the PC ?

    BTW feel free to translate my blog to Chinese, but please link it to my site. Thanks!

    • halherta says:

      Jason, I tried the tutorial with the latest Raspbian OS (2013-07-26) image. Everything worked just fine. Did you copy the /usr and /lib directories from SD card to /rpi directory on Linux PC after installing libgtk3-dev on SD card? Check the size of the ~/rpi/usr and ~/rpi/lib directories on your Linux PC. The first should be at least 1.1GB and the second at least 46.1MB.

  4. Sanjay says:

    Thank you for the tutorial.

    Perhaps I have missed a step or two, but when I run make, I keep getting error on my Ubuntu 12.04 machine that:
    gtktest.c:2.21: fatal error: gtk/gtk.h: No such file or directory
    compilation terminated
    make: *** [all] Error 1

    Where did I go wrong?

    Thanks

    • halherta says:

      this basically means that the compiler is unable to find gtk/gtk.h….so the /usr directory on the RPi was not copied properly to ~/rpi/usr/. Can you verify the size of ~/rpi/usr & ~/rpi/lib directories on your Linux PC/VM?

  5. Sanjay says:

    The size of ~/rpi/usr is 1.3G and ~/rpi/lib is 50M on Linux VM and the same on Raspberry Pi (of /usr and /lib). I ran command on linux VM sudo find / -name gtk.h and sudo find / -name gdk.h, and I got response as:
    /home/sanjay/rpi/usr/include/gtk-3.0/gtk/gtk.h and
    /home/sanjay/rpi/usr/include/gtk-3.0/gdk/gdk.h
    Which means that the gtk/gtk.h file does exist. Any thoughts?

    Thanks

    • halherta says:

      Sanjay,
      This means that the cross-compiler can’t find the gtk.h…but if you look at the makefile you’ll notice that all the appropriate #include directories are included…..

      basically the makefile includes all libraries and library directories that related to the necessary libraries. The exact list can be found by running on the Rpi: echo `pkg-config –libs gtk+-3.0`. The makefile also includes all the necessary #include directories required to build gtk3 apps, which can be discovered by running on the Rpi: echo `pkg-config –cflags gtk+-3.0`.

      This is probably a trivial error of somesort…..are there any errors (due to copying & pasting) in the make file & source file? (you could just download the files…a link is provided) Did you install the described toolchain in the tutorial and include its bin directory in the path variable via .bashrc? I recommend that you retrace all the steps. If you still can’t get it to work…Send me a detailed transcript of exactly what you did…what version of Raspbian you are using e.t.c and with more detailed info, hopefully I can help you make it work.

  6. Jason says:

    Hi, first of all happy new year and thanks again.

    I am using 2013-09-25-wheezy-raspbian, and the size of the ~/rpi/usr and ~/rpi/lib are still a bit larger than 1.1GB and 50MB,

    I have copied the folder usr and lib to the $HOME/rpi:
    ~/rpi$ ls
    lib README(hjj) README(hjj)~ tools-master usr

    what’s more,

    these are the results of running
    “ls -ld /lib/arm-linux-gnueabihf
    ls -ld /usr/lib/arm-linux-gnueabihf”

    lrwxrwxrwx 1 root root 48 Aug 25 19:43 /lib/arm-linux-gnueabihf -> /home/huang87975716/rpi/lib/arm-linux-gnueabihf/

    lrwxrwxrwx 1 root root 52 Aug 25 19:43 /usr/lib/arm-linux-gnueabihf -> /home/huang87975716/rpi/usr/lib/arm-linux-gnueabihf/

    and I am using the ubuntu 12.10 in the VMware on my PC.

    Everything seems fine but still the same error :
    /home/huang87975716/gtktest/gtktest.c:11: undefined reference to `gtk_label_get_type’
    /home/huang87975716/gtktest/gtktest.c:11: undefined reference to `g_type_check_instance_cast’
    /home/huang87975716/gtktest/gtktest.c:11: undefined reference to `gtk_label_set_text’
    /tmp/ccduZmMZ.o: In function `decrease':
    /home/huang87975716/gtktest/gtktest.c:19: undefined reference to `gtk_label_get_type’
    /home/huang87975716/gtktest/gtktest.c:19: undefined reference to `g_type_check_instance_cast’
    /home/huang87975716/gtktest/gtktest.c:19: undefined reference to `gtk_label_set_text’
    /tmp/ccduZmMZ.o: In function `main':
    /home/huang87975716/gtktest/gtktest.c:30: undefined reference to `gtk_init’

    it seems that the file could not found all the functions.

    I am totally messed with all of these.

    Looking forward for your reply, and sincerely happy new year again.

  7. Jason says:

    Would you please send me an email when you reply because I hope I could get your reply in time, thank you soooooo much.

    :)

    • halherta says:

      Jason, I just compiled the example on a Kubuntu 12.04 machine with no problems. Are you using the raspberry pi specific toolchain from “https://github.com/raspberrypi/tools” ?

  8. maurice van hall says:

    If you copy / paste the makefile code, make sure you use a hard tap in the row following “all:” and “clean:”

  9. milton ortiz says:

    great article, very clear, as i can see if i install cubieboard toolchain and follow the procedures it should work too but i have a quaestion…if i have another library besides gtk, i am talking about rf24, i assume it sould work too, right? i wish cubie comunity grows as complete, usefull and interesting as rpi. thanks in advance and thanks again for sharing

  10. milton says:

    i’ve compiled successfully you example, no trouble at all, thanks a lot for throwing light to this dark area.
    i am trying to add another library wich i use and run in my board wich is cubie but as both operating system are based in wheezy the look compatible. the library is from https://github.com/mplatov/librf24-sunxi, it’s to use rf24l01 sensor, as i mentioned before it works in cb, library is in /rpi/usr/local/lib, i’ve adapted your make to compile one of the samples that came with the library, pingtest.cpp…no matter where i copy the library i always receive : arm-linux-gnueabihf/bin/ld: cannot find -lrf24-sunxi but i can see the library in the folder. could you please help me thrying to find an answer? thanks a lot in advance for your time

    • halherta says:

      Milton, I’m not familiar with Cubieboard setups. Can You show me your makefile?

      • milton says:

        thanks for answering.
        as i commented it looks the same if you don’t deal with hardware but the hardware configuration is already solved.
        the library is installed in /usr/local/lib/, it is called rf24 but checking the files i’ve seen two broken links wich point to /usr/local/lib on my cb but the path for crosscompiling is /rpi/usr/local/lib…as i can see that could be part of the trouble. when i check propery of the links, on type it say “link(broken) (inode/symlink)”, anyway here is my make:


        ARM_PREFIX= arm-linux-gnueabihf-
        CC = $(ARM_PREFIX)g++
        SRC += pingtest.cpp
        TARGET = pingtest

        LIBRARY = rf24-sunxi

        LIBRARYDIR += $(HOME)/rpi/lib/arm-linux-gnueabihf
        LIBRARYDIR += $(HOME)/rpi/usr/lib/arm-linux-gnueabihf
        LIBRARYDIR += $(HOME)/rpi/lib
        LIBRARYDIR += $(HOME)/rpi/usr/lib
        LIBRARYDIR += $(HOME)/rpi/usr/local/lib

        XLINK_LIBDIR += $(HOME)/rpi/lib/arm-linux-gnueabihf
        XLINK_LIBDIR += $(HOME)/rpi/usr/lib/arm-linux-gnueabihf

        INCLUDEDIR += $(HOME)/rpi/lib
        INCLUDEDIR += $(HOME)/rpi/usr/local/lib

        OPT = -O0
        DEBUG = -g
        WARN= -Wall
        PTHREAD= -pthread

        INCDIR = $(patsubst %,-I%,$(INCLUDEDIR))
        LIBDIR = $(patsubst %,-L%,$(LIBRARYDIR))
        LIB = $(patsubst %,-l%,$(LIBRARY))
        XLINKDIR = $(patsubst %,-Xlinker -rpath-link=%,$(XLINK_LIBDIR))

        all:
        $(CC) $(OPT) $(DEBUG) $(WARN) $(LIBDIR) $(PTHREAD) $(INCDIR) $(XLINKDIR) $(LIB) $(SRC) -o $(TARGET)

        clean:
        rm -rf $(TARGET)

        if you see something wrong please write a line

        • halherta says:

          Milton,
          You’ll need to remove or comment out these two lines….XLINK_LIBDIR += $(HOME)/rpi/lib/arm-linux-gnueabihf
          XLINK_LIBDIR += $(HOME)/rpi/usr/lib/arm-linux-gnueabihf as they are RPI specific. Also which cross compiler are you using? The Raspberry Pi cross compiler in the git directory that I point to in the article is RapberryPi specific…its optimized for armv6 (ARM11) cores. For the cubieboard you’ll need a different cross compiler that targets ARMy7 (Cortex-A)……The Linaro cross compilers are generally good. I’d recommend you use a GCC 4.6/4.7 one. Sometimes the older ones work better.

          Also you MAY not need these lines as well ..LIBRARYDIR += $(HOME)/rpi/lib/arm-linux-gnueabihf
          LIBRARYDIR += $(HOME)/rpi/usr/lib/arm-linux-gnueabihf

          You’re symlink troubles could also be the culprit.

          good luck!

          • milton ortiz says:

            i’ve compiled the gtk tutorial from you and it worked fine in cubie, it run without trouble, as this is a pretty simple app i thought it could run too but i’ll try the crosscompiler you mention, i’ll let you know

          • milton ortiz says:

            halherta just to let you know….cubie and rpi looks very compatible, i didn’t change anything, i just fixed the broken links in usr/local/lib….compile in ubuntu and worked in cb2 pretty the same, the biggest diferences as i can see (i am absolute newbie, i am not even a programmer) is the hardware, cb have a lot more pins in the two expansion ports and other little things but i am glad it worked and really want to thanks to you for your great tutorials and support

  11. milton ortiz says:

    i know i am off topic by far but can’t get help anywhere. after succesfully compiled the gtk app following your tutorial with some modifications i tried to add xercesc library to read an xml inside my app but with no luck, i can see the library, the headers are in /rpi/usr/include/xercesc the library is in /rpi/usr/lib/arm-linux-gnueabihf/ libxerces-c-3.1.so, no matter how i add the library to the make file it always says can’t find the library…here is my make, i hope somebody can help me:


    ARM_PREFIX= arm-linux-gnueabihf-
    CC = $(ARM_PREFIX)g++
    SRC += gtktest.c
    TARGET = gtktest

    LIBRARY += gtk-3
    LIBRARY += gdk-3
    LIBRARY += atk-1.0
    LIBRARY += gio-2.0
    LIBRARY += pangocairo-1.0
    LIBRARY += gdk_pixbuf-2.0
    LIBRARY += cairo-gobject
    LIBRARY += pango-1.0
    LIBRARY += cairo
    LIBRARY += gobject-2.0
    LIBRARY += glib-2.0
    LIBRARY += rf24-sunxi
    LIBRARY += xerces-c

    LIBRARYDIR += $(HOME)/rpi/lib/arm-linux-gnueabihf
    LIBRARYDIR += $(HOME)/rpi/usr/lib/arm-linux-gnueabihf
    LIBRARYDIR += $(HOME)/rpi/lib
    LIBRARYDIR += $(HOME)/rpi/usr/lib
    LIBRARYDIR += $(HOME)/rpi/usr/local/lib
    LIBRARYDIR += $(HOME)/rpi/usr/include

    XLINK_LIBDIR += $(HOME)/rpi/lib/arm-linux-gnueabihf
    XLINK_LIBDIR += $(HOME)/rpi/usr/lib/arm-linux-gnueabihf

    INCLUDEDIR += $(HOME)/rpi/usr/include/gtk-3.0
    INCLUDEDIR += $(HOME)/rpi/usr/include/pango-1.0
    INCLUDEDIR += $(HOME)/rpi/usr/include/gio-unix-2.0/
    INCLUDEDIR += $(HOME)/rpi/usr/include/atk-1.0
    INCLUDEDIR += $(HOME)/rpi/usr/include/cairo
    INCLUDEDIR += $(HOME)/rpi/usr/include/gdk-pixbuf-2.0
    INCLUDEDIR += $(HOME)/rpi/usr/include/freetype2
    INCLUDEDIR += $(HOME)/rpi/usr/include/glib-2.0
    INCLUDEDIR += $(HOME)/rpi/usr/lib/arm-linux-gnueabihf/glib-2.0/include
    INCLUDEDIR += $(HOME)/rpi/usr/include/pixman-1
    INCLUDEDIR += $(HOME)/rpi/usr/include/libpng12
    INCLUDEDIR += $(HOME)/rpi/usr/local/lib
    INCLUDEDIR += $(HOME)/rpi/usr/include/xercesc

    OPT = -O0
    DEBUG = -g
    WARN= -Wall
    PTHREAD= -pthread

    INCDIR = $(patsubst %,-I%,$(INCLUDEDIR))
    LIBDIR = $(patsubst %,-L%,$(LIBRARYDIR))
    LIB = $(patsubst %,-l%,$(LIBRARY))
    XLINKDIR = $(patsubst %,-Xlinker -rpath-link=%,$(XLINK_LIBDIR))

    all:
    $(CC) $(OPT) $(DEBUG) $(WARN) $(LIBDIR) $(PTHREAD) $(INCDIR) $(XLINKDIR) $(LIB) $(SRC) -o $(TARGET)

    clean:
    rm -rf $(TARGET)

    thanks a lot in advance

    • halherta says:

      Milton, just a shot in the dark….replace ‘LIBRARY += xerces-c’ with ‘LIBRARY += xerces-c-3.1′. Also the xerces library…..does that have any other dependencies? if it does…you’ll have to add those into the makefile……

      make sure you install xerces on the RPI and before you copy the /usr & /lib directories of the RPi’s SD card into the /pi directory on your PC

      • milton ortiz says:

        thanks as always for answering. i’ve done both of your comments, xerces-c-3.1 and yes, i installed before copying libraries to my pc, what is left are the dependencies wich i don’t have a clue how to determine that, how can i know it?? sorry if bothering too much

        • halherta says:

          Milton, It doesn’t seem to need any particular dependencies.

          http://xerces.apache.org/xerces-c/faq-distrib-3.html#faq-2

          What error do you have exactly? are the softlinks still functional?
          sudo ln -s $HOME/rpi/usr/lib/arm-linux-gnueabihf/ /usr/lib/arm-linux-gnueabihf
          sudo ln -s $HOME/rpi/lib/arm-linux-gnueabihf/ /lib/arm-linux-gnueabihf

          • milton ortiz says:

            softlinks are actually working, if i don’t try to include xerces gtk works fine.
            i add “#include ”
            and i always receive error: c:5:42: fatal error: xercesc/util/PlatformUtils.hpp: no such files or directory.
            i can see the file is on that route but compiler seems cannot find it

  12. milton ortiz says:

    accidentally i deleted the include line, here is the message complete:

    softlinks are actually working, if i don’t try to include xerces gtk works fine.
    i add “#include xercesc/util/PlatformUtils.hpp”
    and i always receive error: c:5:42: fatal error: xercesc/util/PlatformUtils.hpp: no such files or directory.
    i can see the file is on that route but compiler seems cannot find it

    • milton ortiz says:

      i got the answer, it was in the path i was specifing….instead of INCLUDEDIR += $(HOME)/rpi/usr/include/xercesc it should be… INCLUDEDIR += $(HOME)/rpi/usr/include/

      thanks a lot for your time.

  13. Pingback: crosscompiling xerces in linux for raspberry pi

  14. milton ortiz says:

    i have some difficulty understanding your make in order to finish compiling the xerces part and maybe you can throw some light again, i have to include docDomDocument.cpp and docDomDocument.h, when i do make it says “unreference file”, as i have read i have to compile as an object docDomDocument.cpp to add it to main.cpp, i’ve read enough about but it is pretty difficult to me trying to implement what i have found to the way your make is structured (kind of: g++ -c docDomDocument.cpp -o docDomDocument.o // g++ docDomDocument.o main.cpp).
    could you please guide me again on this? hope not being a pain in the @$$.

    • halherta says:

      replace ‘SRC += gtktest.c’ with ‘SRC = gtktest.c docDomDocument.cpp’ . Make sure that there is a space between the names of both source files. Alternatively you can do the following on two separate lines: ‘SRC += gtktest.c’ and the line below it ‘SRC += docDomDocument.cpp’. Also add the directory containing your include file docDomDocument.h to the INCLUDEDIR variable i.e. ‘INCLUDEDIR += /path/tofoldercontainingheaderfile’.

      That should add these header/source code files to the build process. Makefiles can get weird. And use the most obfuscated syntax. CMake is supposed to be a better way of organizing builds….and it is…. but I’m more used to Makefiles….despite their messed up syntax.

      • milton ortiz says:

        i am missing something, in the documentation i’ve read docDomDocument.cpp should be added to gtktest (g++ docDomDocument.o gtktest.cpp)that’s my main cofusion, doing what you say i’ll get two separate objects, isn’t it?

      • milton ortiz says:

        you are great, thanks a lot for all your help and most of all being patience enough to answer my questions, it worked pretty fine

  15. Alberto says:

    Hi,
    I do not understand why I get this error message:
    /raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: warning: libgraphite2.so.2.0.0, needed by /raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libharfbuzz.so.0, not found (try using -rpath or -rpath-link)
    /raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libharfbuzz.so.0: undefined reference to `gr_seg_advance_X’
    /raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libharfbuzz.so.0: undefined reference to `gr_slot_can_insert_before’
    /raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libharfbuzz.so.0: undefined reference to `gr_make_face’
    …..
    …..

    Can someone give me a hint please ?
    thanks Alb

    • Joe Wronski says:

      I added XLINK_LIBDIR += $(HOME)/rpi/usr/lib to the makefile to fix the first error, and the rest went away. This is because find ../rpi -name libgraphite2.so.2.0.0 -print yielded ../rpi/usr/lib/libgraphite2.so.2.0.0

  16. Ray Bahr says:

    To answer Alberto’s question, please see: http://sysprogs.com/blog/?p=54

    Ray

  17. Joe Wronski says:

    I had 2 snags, otherwise this worked fine. First, I could not read the SD card to pull the usr and lib from the Pi FS. So, I used scp -r to copy th files. This may have had undesired effects on any symbolic links in the pi FS. Or not. The second snag was Make gave an error
    warning: libgraphite2.so.2.0.0, needed by /home/joe/rpi/usr/lib/arm-linux-gnueabihf/libharfbuzz.so.0, not found (try using -rpath or -rpath-link)
    So, I researched a bit and added a line to Makefile:
    XLINK_LIBDIR += $(HOME)/rpi/usr/lib
    Then it “just worked”.
    A great start, and I want to work on a kiosk type app now.
    Thanks, and cheers!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>