Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
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
Old 08-29-2012, 11:18 AM   #2
twobob
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Týr
twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.
 
twobob's Avatar
 
Posts: 6,491
Karma: 5977000
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
*patter of applause*
Attached Thumbnails
Click image for larger version

Name:	TightVNC: kindle:0.0_080.png
Views:	141
Size:	9.4 KB
ID:	98023  

Last edited by twobob; 12-20-2012 at 10:06 PM.
twobob is offline   Reply With Quote
Old 08-29-2012, 11:31 AM   #3
knc1
Embedded Cheerleader
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 5,773
Karma: 5722276
Join Date: Feb 2012
Device: Too many.
ldconfig is usually used to update the **system** cache and library sym-links . . .
But it can also be used to create the proper sym-links of a manually specified directory.

In this thread, it could be used in place of that long list of manually entered "ln -s ..." commands. Details in the ldconfig manual page.

O.T:
No number of simlies substitutes for public courtesy, even when you disagree with someone.

Last edited by knc1; 08-29-2012 at 11:35 AM.
knc1 is offline   Reply With Quote
Old 08-29-2012, 12:50 PM   #4
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
Quote:
Originally Posted by knc1 View Post
ldconfig is usually used to update the **system** cache and library sym-links . . .
But it can also be used to create the proper sym-links of a manually specified directory.

In this thread, it could be used in place of that long list of manually entered "ln -s ..." commands. Details in the ldconfig manual page.

O.T:
No number of simlies substitutes for public courtesy, even when you disagree with someone.
I'm really *very* sorry if my "attempt" at humour has upset you in any way that was not my intent.

I'd be interested in how you'd use ldconfig like this, would bad sym links need removing manually first?
chris_c is offline   Reply With Quote
Old 08-29-2012, 12:59 PM   #5
knc1
Embedded Cheerleader
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 5,773
Karma: 5722276
Join Date: Feb 2012
Device: Too many.
No delete required, it will correct the soname conventions.
man ldconfig
should give the details.
Hmm...
-v verbose (sounds nice)
-n only process directories on the command line
-N don't rebuild the cache
-f conf use conf instead of /etc/ld.so.conf
-r root change to and use root as the root directory
All sound like likely members of a command to manually fix those links.
There may be more info in the man page.
Be sure to always use "-N" so you don't trash your system cache.
knc1 is offline   Reply With Quote
Old 08-29-2012, 01:03 PM   #6
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
I'd already read the man page before posting the tutorial - I was however unable to get it to work as I wanted - how would you do it?
chris_c is offline   Reply With Quote
Old 08-29-2012, 01:05 PM   #7
knc1
Embedded Cheerleader
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 5,773
Karma: 5722276
Join Date: Feb 2012
Device: Too many.
What did you do?
What where the results?
Please be specific, we can't see the command(s) you are typing.
knc1 is offline   Reply With Quote
Old 08-29-2012, 02:41 PM   #8
sandman7920
Junior Member
sandman7920 has a spectacular aura aboutsandman7920 has a spectacular aura aboutsandman7920 has a spectacular aura aboutsandman7920 has a spectacular aura aboutsandman7920 has a spectacular aura aboutsandman7920 has a spectacular aura aboutsandman7920 has a spectacular aura aboutsandman7920 has a spectacular aura aboutsandman7920 has a spectacular aura aboutsandman7920 has a spectacular aura aboutsandman7920 has a spectacular aura about
 
Posts: 6
Karma: 4348
Join Date: Jul 2012
Device: K4NT
ldconfig will create symlink only to soname attribute used in linker
if we have
g++ -Wl,-soname,libmylib.so.2 -shared -o output/libmylib.so.2.0.1 -fPIC main.o

ldconfig -N /some/place/lib
will create libmylib.so.2 -> libmylib.so.2.0.1

libmylib.so will not be created automatically libmylib.so is not needed to run application it is needed only for linker

P.S. Sorry for my english
sandman7920 is offline   Reply With Quote
Old 08-29-2012, 03:34 PM   #9
knc1
Embedded Cheerleader
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 5,773
Karma: 5722276
Join Date: Feb 2012
Device: Too many.
That is correct.

-lmylib ==> libmylib.so for the linkage step of compiling.

The Kindle system images have these "development" links removed from the shipped image.
The O.P. was originally renaming the most specific name (actual file) to the development name.
knc1 is offline   Reply With Quote
Old 12-21-2012, 12:01 AM   #10
twobob
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Týr
twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.
 
twobob's Avatar
 
Posts: 6,491
Karma: 5977000
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
Step 1) me@dev ~/k3-dev $ CFLAGS="-U_FORTIFY_SOURCE -fno-stack-protector -O2 -fno-finite-math-only -ffast-math -march=armv6j -mtune=arm1136jf-s -mfpu=vfp -pipe -fomit-frame-pointer -fPIC" /opt/arm-2007q3/bin/arm-none-linux-gnueabi-gcc test.c -o test `~/GIT/buildroot-2012.03/output/host/usr/bin/pkg-config gtk+-2.0 --cflags` -L~/GIT/buildroot/output/host/usr/arm-unknown-linux-gnueabi/sysroot/lib/ -L./lib/ -lgtk-directfb-2.0 -lgdk-directfb-2.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lpixman-1 -lpng12 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lfontconfig -lfreetype -lz -lexpat -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -ljpeg -ldirectfb-1.2 -lfusion -ldirect-1.2

That works for a 3. will make okay

2007q3 TC, using "loaned" headers from another TC for those parts that 2007 can not build.

Step 2) prep directfb
[root@kindle bin]# cat > /tmp/root/.directfbrc
no-vt
linux-input-devices=/dev/input/event0,/dev/input/event1


Step 3) run it

Quote:
[root@kindle bin]# ./test
Spoiler:

~~~| DirectFB 1.2.0 |~~~~~~~
(c) 2001-2008 The world wide DirectFB Open Source Community
(c) 2000-2004 Convergence (integrated media) GmbH
----------------------------------------------------------------

(*) DirectFB/Core: Single Application Core. (2012-09-01 19:47)
(!) Direct/Modules: Unable to dlopen `/usr/lib/directfb-1.2-0/systems/libdirectfb_devmem.so'!
--> /usr/lib/directfb-1.2-0/systems/libdirectfb_devmem.so: undefined symbol: system_set_mode
(*) Direct/Thread: Started 'Linux Input' (-1) [INPUT OTHER/OTHER 0/0] <8388608>...
(*) DirectFB/Input: mxckpd (1) 0.1 (directfb.org)
(*) Direct/Thread: Started 'Linux Input' (-1) [INPUT OTHER/OTHER 0/0] <8388608>...
(*) DirectFB/Input: fiveway (2) 0.1 (directfb.org)
(*) DirectFB/Graphics: Generic Software Rasterizer 0.6 (directfb.org)
(*) DirectFB/Core/WM: Default 0.3 (directfb.org)
(*) FBDev/Mode: Setting 600x800 videomode x=600, y=800
(*) FBDev/Mode: Setting 600x800 videomode x=600, y=706
(*) FBDev/Mode: Setting 600x800 videomode x=800, y=506
(*) FBDev/Mode: Setting 600x800 videomode x=800, y=600
(*) FBDev/Mode: Setting 600x800 videomode x=600, y=800
(*) FBDev/Mode: Setting 600x800 videomode x=600, y=706
(*) FBDev/Mode: Setting 600x800 videomode x=800, y=506
(*) FBDev/Mode: Setting 600x800 videomode x=800, y=600
(*) FBDev/Mode: Setting 600x800 videomode x=600, y=800
(*) FBDev/Mode: Setting 600x800 videomode x=600, y=706
(*) FBDev/Mode: Setting 600x800 videomode x=800, y=506
(*) FBDev/Mode: Setting 600x800 videomode x=800, y=600
(*) FBDev/Mode: Setting 600x800 videomode x=600, y=800
(*) FBDev/Mode: Setting 600x800 videomode x=600, y=706
(*) FBDev/Mode: Setting 600x800 videomode x=800, y=506
(*) FBDev/Mode: Setting 600x800 videomode x=800, y=600
(*) FBDev/Mode: Setting 600x800 videomode x=600, y=800
(*) FBDev/Mode: Setting 600x800 videomode x=600, y=706
(*) FBDev/Mode: Setting 600x800 videomode x=800, y=506
(*) FBDev/Mode: Setting 600x800 videomode x=800, y=600
(*) FBDev/Surface: Allocated 600x800 8 bit LUT8 buffer (index 0) at offset 0 and pitch 600.
(*) FBDev/Mode: Setting 600x800 videomode x=600, y=800
(*) FBDev/Mode: Setting 600x800 videomode x=600, y=706
(*) FBDev/Mode: Setting 600x800 videomode x=800, y=506
(*) FBDev/Mode: Setting 600x800 videomode x=800, y=600
(!!!) *** WARNING [Non-flipping window surface and no 'autoflip-window' option used] *** [idirectfbsurface_window.c:310 in IDirectFBSurface_Window_Construct()]
in _gdk_windowing_window_init creating primary surface window - w=600, h=800
create_directfb_window( 600x 800, caps 0x00000009 )

(test:19609): Gdk-CRITICAL **: gdk_drawable_set_colormap: assertion `cmap == NULL || gdk_drawable_get_depth (drawable) == cmap->visual->depth' failed
(*) Direct/Thread: Started 'EventBufferFeed' (-1) [MESSAGING OTHER/OTHER 0/0] <8388608>...
create_directfb_window( 100x 48, caps 0x00000001 )

(test:19609): Gdk-DirectFB-WARNING **: gdk_window_set_keep_above() not implemented.

(test:19609): Gdk-DirectFB-WARNING **: gdk_window_set_keep_below() not implemented.
Step 4) [root@kindle root]# echo 1 > /proc/eink_fb/update_display
for quick redraw testing. assumedly this could be shoved into a relevant repaint event.

but a worker.
Attached Thumbnails
Click image for larger version

Name:	Screenshot from 2012-12-21 17:20:01.png
Views:	113
Size:	7.2 KB
ID:	98045  

Last edited by twobob; 12-21-2012 at 12:22 PM.
twobob is offline   Reply With Quote
Reply

Tags
k5 tools

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Kindle VNC viewer (native app, GPLv2) hawhill Kindle Developer's Corner 448 03-16-2014 01:03 PM
What different between HTML5 APP(build by phonegap) & Native APP sevenxtars Android Developer's Corner 1 06-29-2012 02:03 AM
Tablet Questions about NT's native reader app bfollowell Nook Color & Nook Tablet 0 02-06-2012 02:18 PM
iLiad Compile GTK application on Iliad. Help vschmidt iRex Developer's Corner 9 11-25-2008 01:49 AM
Compile application gtk+ with liberdm Kiba iRex 1 07-05-2008 10:30 AM


All times are GMT -4. The time now is 10:47 AM.


MobileRead.com is a privately owned, operated and funded community.