View Single Post
Old 08-29-2012, 10:55 AM   #1
chris_c
Member Retired
chris_c can bend spoons with a thought.chris_c can bend spoons with a thought.chris_c can bend spoons with a thought.chris_c can bend spoons with a thought.chris_c can bend spoons with a thought.chris_c can bend spoons with a thought.chris_c can bend spoons with a thought.chris_c can bend spoons with a thought.chris_c can bend spoons with a thought.chris_c can bend spoons with a thought.chris_c can bend spoons with a thought.
 
Posts: 38
Karma: 134098
Join Date: Aug 2012
Device: kindle touch
here's how to compile a gtk native app for the kindle touch

I present here by way of a loose tutorial sufficient instruction to begin programming a native gtk application without needing to chroot into some large build environment.... , I'm assuming Ubuntu Linux here but any Linux should be workable...

install the package gcc-4.6-arm-linux-gnueabi this *should* install everything else that you need as well.

You also need to install libgtk2.0-dev we'll be using this as a convienience for the headers, don't worry that you have somehow have gtk PC headers and you surely need gtk ARM headers regardless of platform they're all the same thing and in any case we'll be using an ARM compiler with them.... ( so let's not hear any more on the subject - you know who you are )

make a place were we can set stuff up
Code:
mkdir kindle-dev
cd kindle-dev
fisrt we'll grab the libs we need from the kindle
Code:
 
ssh root@kindle
cd /usr
tar -cpvzf /mnt/us/libs.tar.gz lib
exit
this tar ball should be created as I have above, if you've got the symlinks and not copied libs multiple times (will break our builds later) the tar ball should be around 35mb

Code:
scp root@<your kindles ip address>:/mnt/us/libs.tar.gz .
ssh root@<your kindles ip address> rm /mnt/us/libs.tar.gz
tar zxvf libs.tar.gz
its probably worth cd-ing into the lib directory and just checking you have the libs and their sym links all okay...

alas some are NOT linked relative....
Code:
cd lib
rm libglib-2.0.so
rm libglib-2.0.so.0
ln -s libglib-2.0.so.0.2918.0 libglib-2.0.so
ln -s libglib-2.0.so.0.2918.0 libglib-2.0.so.0
rm libgio-2.0.so
rm libgio-2.0.so.0
ln -s libgio-2.0.so.0.2918.0 libgio-2.0.so
ln -s libgio-2.0.so.0.2918.0 libgio-2.0.so.0
rm libgobject-2.0.so
rm libgobject-2.0.so.0
ln -s libgobject-2.0.so.0.2918.0 libgobject-2.0.so
ln -s libgobject-2.0.so.0.2918.0 libgobject-2.0.so.0
rm libffi.so
rm libffi.so.5
ln -s libffi.so.5.0.10 libffi.so
ln -s libffi.so.5.0.10 libffi.so.5
rm libgmodule-2.0.so
rm libgmodule-2.0.so.0
ln -s libgmodule-2.0.so.0.2918.0 libgmodule-2.0.so
ln -s libgmodule-2.0.so.0.2918.0 libgmodule-2.0.so.0
rm libgthread-2.0.so
rm libgthread-2.0.so.0
ln -s libgthread-2.0.so.0.2918.0 libgthread-2.0.so
ln -s libgthread-2.0.so.0.2918.0 libgthread-2.0.so.0
cd ..
you may discover others depending what libs you use.... (I will resist the urge to pass comment on whomever linked these files with an absolute path)

We're going to use this simple example to prove everything works, so plagiarise and paste errrm I mean copy and paste this into a file called test.c and save it to our work directory
Code:
#include <gtk/gtk.h>

static void hello( GtkWidget *widget,gpointer data ) {
    gtk_main_quit ();
}

static gboolean delete_event( GtkWidget *widget, GdkEvent  *event, gpointer   data ) {
    g_print ("delete event occurred\n");
    return FALSE; // we do want to quit
}

static void destroy( GtkWidget *widget, gpointer   data ) {
    gtk_main_quit ();
}

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

    GtkWidget *window;
    GtkWidget *button;

    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    g_signal_connect (window, "delete-event", G_CALLBACK (delete_event), NULL);
    g_signal_connect (window, "destroy", G_CALLBACK (destroy), NULL);
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
    button = gtk_button_new_with_label ("Hello World");
    g_signal_connect (button, "clicked", G_CALLBACK (hello), NULL);
    gtk_container_add (GTK_CONTAINER (window), button);
    gtk_window_set_title ( GTK_WINDOW(window) , "L:A_N:application_ID:test");
    gtk_widget_show_all (window);

    gtk_main ();
    return 0;
}
first of all lets just make sure we can compile it all okay on the PC - after all one of the nice things is that we can compile, run and test our apps on the PC and just test now and again on the kindle, this makes developing much faster and easier!

Code:
gcc test.c -o test `pkg-config gtk+-2.0 --cflags --libs`
Notice the back tick operator ( ` ) this is the character above the tab key (usually!) this replaces the command with the output of pkg-config which in the case of gtk makes a whole load of spew because gtk uses a LOT of libraries - but then thats what makes it so useful! ( that and the fact it's C and not some insane language like c++ )

one thing to note is that unlike most "normal" apps this one has been given a wierd title
Code:
    gtk_window_set_title ( GTK_WINDOW(window) , "L:A_N:application_ID:test");
The kindle will only show windows with a sepcific title - the way this title is encoded is also very "interesting" - I would recommend reading the forum post about this discovery...

So now to actually (finally!) compile a kindle executable :-o

take a deep breath its a commmand and a half....
Code:
arm-linux-gnueabi-gcc-4.6 test.c -o test `pkg-config gtk+-2.0 --cflags` -L/usr/arm-linux-gnueabi/lib/ -L./lib/ -lgtk-x11-2.0 -lgdk-x11-2.0 -lXrender -lXinerama -lXext -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lXdamage -lXfixes -latk-1.0 -lcairo -lpixman-1 -lpng12 -lxcb-shm -lxcb-render -lX11 -lxcb -lXau -lXdmcp -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lfontconfig -lfreetype -lz -lexpat -lgobject-2.0 -lffi -lgmodule-2.0 -lgthread-2.0 -lglib-2.0
obviously if you were using a makefile you'd use a variable for the libs...
Code:
LIBS = -lgtk-x11-2.0 -lgdk-x11-2.0 ... etc!

bogus: bogus.c
	arm-linux-gnueabi-gcc-4.6 $(LIBS) ....
so now to test!
Code:
scp test root@<your kindles ip address>:/mnt/us/
ssh root@<your kindles ip address>
/mnt/us/test
It should be noted that the way a gtk app on the kindle lays out and displays its widgets is different to the rest of the world.
Amazon have played fast and loose with gtk in away I'm not too sure I'm terribly impressed with....

Taking it further - well ya on ya own


I will not answer general questions about gcc not gtk programming, I will however gladly answer specifics to do with this method of creating a kindle native application....

Enjoy!
chris_c is offline   Reply With Quote