Building a hello world application

From Openmoko

(Difference between revisions)
Jump to: navigation, search
m (Compiling it using bitbake)
m (user -> username)
Line 87: Line 87:
 
=== Compiling it using bitbake ===
 
=== Compiling it using bitbake ===
 
If you set your enviroment (I created a small script to do this, you could also add it to you .bashrc)
 
If you set your enviroment (I created a small script to do this, you could also add it to you .bashrc)
  export OMDIR=/home/user/moko
+
  export OMDIR=/home/username/moko
 
  export BBPATH=$OMDIR/build:$OMDIR/openmoko/trunk/oe:$OMDIR/openembedded
 
  export BBPATH=$OMDIR/build:$OMDIR/openmoko/trunk/oe:$OMDIR/openembedded
 
You should be capable of
 
You should be capable of

Revision as of 11:24, 6 October 2007

Contents

Preparation

This guide assumes that you have performed the steps in Building_OpenMoko_from_scratch

The commandline program

Store the following more or less standard hello world code in hello.c

#include <stdio.h>

int main()
{
  printf ("Hello World\n");
  return 0;
}

Compiling it the wrong / easy way

Assuming your current working directory is /home/moko, and that you stored the code in /home/moko/hello.c it should now be possible to compile the application using

./build/tmp/cross/arm-linux/bin/gcc -o hello hello.c

Testing it

Assuming you have followed Setting up USB connection and you have a working network connection to either a qemu Neo or a real Neo.

scp hello root@192.168.0.202:/tmp/
ssh root@192.168.0.202 /tmp/hello

This sequence of commands ought to give you a nice Hello World, btw. the default root password is blank, just press return.

GDK the Wrong / Easy Way

Building a GDK application the wrong way is slightly more complex, but is still fun to try. It requires using pkg-config to specify including and linking with the ARM header files and libraries.

Given the following program as main.c:

#include <gtk/gtk.h>

gchar *hello = "Howdy";
gchar *world = "World";
GtkWidget *label;
gchar *labeltext;

void buttoncb(GtkWidget *widget, gpointer data)
{
if (labeltext == hello)
   {
   labeltext = world;
   gtk_label_set_text(GTK_LABEL(label), labeltext);
   }
else if (labeltext == world)
   gtk_main_quit();
}

int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *button;

gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
button = gtk_button_new();
labeltext = hello;
label = gtk_label_new(labeltext);
gtk_container_add(GTK_CONTAINER(button), label);
g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(buttoncb), NULL);
gtk_container_add(GTK_CONTAINER(window), button);
gtk_widget_show_all(window);
gtk_main();

return 0;
}

You must first point pkg-config to the proper directory:

export PKG_CONFIG_PATH=/home/username/moko/build/tmp/staging/arm-linux/lib/pkgconfig

And set up an environment variable to make things easier:

export OM=/home/username/moko

The compile/link line is rather long - you will only want to do this once before you decide to create a shell script or make file:

$OM/build/tmp/cross/arm-linux/bin/gcc -L$OM/build/tmp/staging/arm-linux/lib
  -Wl,-rpath-link,$OM/build/tmp/staging/arm-linux/lib -Wl,-O1 -g -o hw main.c
  `$OM/build/tmp/staging/i686-linux/bin/pkg-config --cflags --libs openmoko-libs
  gtk+-2.0`

Then copy and run as in the original hello world command line program above.

Why was it the wrong way?

OpenMoko uses [OpenEmbedded] and they use bitbake when building stuff, but at least you now know that you can cross compile for OpenMoko.

Compiling it using bitbake

If you set your enviroment (I created a small script to do this, you could also add it to you .bashrc)

export OMDIR=/home/username/moko
export BBPATH=$OMDIR/build:$OMDIR/openmoko/trunk/oe:$OMDIR/openembedded

You should be capable of

cd $OMDIR/build
bitbake nano

This should auto-magically fetch the recipe for baking nano and baking it. This results in some ipk packages being created in $OMDIR/build/tmp/deploy/ipk/armv4t/ According to [UsefulTargets | OpenEmbedded] there is a helloworld target, however on my machine it fails with 'ERROR: Nothing provides dependency helloworld'
While this hasn't brought us closer to actually baking a helloworld it demonstrates what we should eventually be capable of doing for our new and revolutionary software for OpenMoko.

An OpenEmbedded guide to creating a hello world

OpenEmbedded has a nice [Wiki page] on creating a hello world, I highly recommend it.

Creating an ipk package

To be written (Perhaps this is done by the do_install() function)

Personal tools

Preparation

This guide assumes that you have performed the steps in Building_OpenMoko_from_scratch

The commandline program

Store the following more or less standard hello world code in hello.c

#include <stdio.h>

int main()
{
  printf ("Hello World\n");
  return 0;
}

Compiling it the wrong / easy way

Assuming your current working directory is /home/moko, and that you stored the code in /home/moko/hello.c it should now be possible to compile the application using

./build/tmp/cross/arm-linux/bin/gcc -o hello hello.c

Testing it

Assuming you have followed Setting up USB connection and you have a working network connection to either a qemu Neo or a real Neo.

scp hello root@192.168.0.202:/tmp/
ssh root@192.168.0.202 /tmp/hello

This sequence of commands ought to give you a nice Hello World, btw. the default root password is blank, just press return.

GDK the Wrong / Easy Way

Building a GDK application the wrong way is slightly more complex, but is still fun to try. It requires using pkg-config to specify including and linking with the ARM header files and libraries.

Given the following program as main.c:

#include <gtk/gtk.h>

gchar *hello = "Howdy";
gchar *world = "World";
GtkWidget *label;
gchar *labeltext;

void buttoncb(GtkWidget *widget, gpointer data)
{
if (labeltext == hello)
   {
   labeltext = world;
   gtk_label_set_text(GTK_LABEL(label), labeltext);
   }
else if (labeltext == world)
   gtk_main_quit();
}

int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *button;

gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
button = gtk_button_new();
labeltext = hello;
label = gtk_label_new(labeltext);
gtk_container_add(GTK_CONTAINER(button), label);
g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(buttoncb), NULL);
gtk_container_add(GTK_CONTAINER(window), button);
gtk_widget_show_all(window);
gtk_main();

return 0;
}

You must first point pkg-config to the proper directory:

export PKG_CONFIG_PATH=/home/username/moko/build/tmp/staging/arm-linux/lib/pkgconfig

And set up an environment variable to make things easier:

export OM=/home/username/moko

The compile/link line is rather long - you will only want to do this once before you decide to create a shell script or make file:

$OM/build/tmp/cross/arm-linux/bin/gcc -L$OM/build/tmp/staging/arm-linux/lib
  -Wl,-rpath-link,$OM/build/tmp/staging/arm-linux/lib -Wl,-O1 -g -o hw main.c
  `$OM/build/tmp/staging/i686-linux/bin/pkg-config --cflags --libs openmoko-libs
  gtk+-2.0`

Then copy and run as in the original hello world command line program above.

Why was it the wrong way?

OpenMoko uses [OpenEmbedded] and they use bitbake when building stuff, but at least you now know that you can cross compile for OpenMoko.

Compiling it using bitbake

If you set your enviroment (I created a small script to do this, you could also add it to you .bashrc)

export OMDIR=/home/user/moko
export BBPATH=$OMDIR/build:$OMDIR/openmoko/trunk/oe:$OMDIR/openembedded

You should be capable of

cd $OMDIR/build
bitbake nano

This should auto-magically fetch the recipe for baking nano and baking it. This results in some ipk packages being created in $OMDIR/build/tmp/deploy/ipk/armv4t/ According to [UsefulTargets | OpenEmbedded] there is a helloworld target, however on my machine it fails with 'ERROR: Nothing provides dependency helloworld'
While this hasn't brought us closer to actually baking a helloworld it demonstrates what we should eventually be capable of doing for our new and revolutionary software for OpenMoko.

An OpenEmbedded guide to creating a hello world

OpenEmbedded has a nice [Wiki page] on creating a hello world, I highly recommend it.

Creating an ipk package

To be written (Perhaps this is done by the do_install() function)