View Single Post
Posts: 53 | Thanked: 51 times | Joined on Feb 2010
#2
Some people may prefer to use Scratchbox, so the following will help you setup Scratchbox and create a "Hello World" program.

1. Install Scratchbox

Scratchbox is, taken from the scrachbox website:
Scratchbox is a cross-compilation toolkit designed to make embedded Linux application development easier. It also provides a full set of tools to integrate and cross-compile an entire Linux distribution.
First, you will need to ensure that xserver-xephyr is installed on your system. Xephyr is an X server that can be run inside another X server. Xephyr will create a window that scratchbox can populate with the N900 emulator or "Window".

Use your package manager or control panel or what ever you use to manage installed programs to install Xephyr. For example, in Linux Mint, I can use the "Package Manager".

Once installed, download the SDK python script and install it. Note, if the script fails to run, it is because you do not have Python installed. Again, go to your package manager and install Python. However, on Linux Mint, when I ran the script, it installed Python on its own.

Download from http://repository.maemo.org/stable/5...-wizard_5.0.py

Open up a new terminal and run the following:

First we make it executable:
Code:
chmod a+x maemo-sdk-install-wizard_5.0.py
Then run as root:
If you use Ubuntu:
Code:
sudo ./maemo-sdk-install-wizard_5.0.py
or if you use Debian:
Code:
su -c ./maemo-sdk-install-wizard_5.0.py
or if the above does not work, try:
Code:
su
enter your root password and then
Code:
./maemo-sdk-install-wizard_5.0.py
A Scratchbox install window should appear, follow the options untill you get to the installing now part.

Note, this will take a long time as you need to download a lot of data ~600mb. You best grab a coffee!

If Scratchbox fails to install due to "too many errors", the following should work. There is a known bug in the installer so this is a quick workaround:

Open up a terminal window and edit the following file:
Code:
/etc/sysctl.conf
Add the line to the bottom of the file:
Code:
vm.mmap_min_addr = 0
Save and exit

Then run:
Code:
sudo sysctl -p
No try running scratchbox again:
Code:
sudo ./maemo-sdk-install-wizard_5.0.py
It should continue from where it left off.

2. Update Scratchbox

Hopefully Scratchbox installed successfully. Now we just need to update Scratchbox and add all the Qt libraries so we can run Qt apps.

Open up a terminal window and login to Scratchbox:
login to scratchbox:
Code:
/scratchbox/login
Hopefully you will get the following prompt:
PHP Code:
user@linuxmint ~/Desktop $ /scratchbox/login

Welcome to Scratchbox
the cross-compilation toolkit!

Use 
'sb-menu' to change your compilation target.
See /scratchbox/doc/ for documentation.

[
sbox-FREMANTLE_X86: ~] > 

First, we need to add the extras repositories:
Code:
vim /etc/apt/sources.list
Now use the arrow keys to get to am empty spot, press the i key which will turn the mode to insert and type out the following:

Code:
#Extras
deb http://repository.maemo.org/extras/ fremantle free non-free
deb-src http://repository.maemo.org/extras/ fremantle free
If you make a mistake, hit the Escape key and type :q! and hit enter and vim will quit without saving. Once your happy you have typed everything correctly, hit Escape and :w and enter to save the file. Then to quick, press Escape and then type :q

You can now go ahead an update apt’s local cache:
Code:
fakeroot apt-get update
Now we want to check we have the latest distribution. Type:
Code:
fakeroot apt-get dist-upgrade
Now Scratchbox is updated, so we need to add the Qt libraries, type:
Code:
fakeroot apt-get install libqt4-gui libqt4-dev
Exit Scratchbox by typing exit and close your terminal.

We are now ready to try out Scratchbox to see if it run the N900 "emulator".

By default the SDK requires a Xephyr window, simply double clicking on the Desktop icon will not work.

So lets edit that script so it creates the window for us so we only have one icon we need to double click.

Edit the /usr/local/bin/start_xephyr.sh file and add code to run a window. This should be a single line only, sorry but the forum wraps the line:
Code:
(Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac -keybd ephyr,,,xkbmodel=evdev) &
So the file becomes:
Code:
#!/bin/sh
# Automatically created by Maemo 5.0 SDK Installer
(Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac -keybd ephyr,,,xkbmodel=evdev) &
(Xephyr :2 -host-cursor -screen 800x480x16 -dpi 96 -ac -kb; newgrp sbox <<'END'
/scratchbox/login af-sb-init.sh stop
END
) &
newgrp sbox <<'END'
sleep 3
/scratchbox/login sb-conf select FREMANTLE_X86
/scratchbox/login af-sb-init.sh restart
END
Save and double click the SDK icon and you should now have working window.

Now you are ready to to try your hello world program!. Close any windows that are still open.

3. Hello world

The Nokia SDK will create a windows which will show us a N900 window. We will still need to use a separate terminal to "inject" our code.

So lets begin by creating the basic hello world program. On your desktop, you should find a sbhome icon. Double clicking this will take you to the /scratchbox/users/username/home/username

Essentially, /scratchbox contains all of maemo so it is the "root" of the phone.

Anyway, enter the sbhome and create a new directory called "HelloWorld". I believe in most linux window managers, you can right click and then Create Folder.

Now open an editor of some sort, example, GEdit and paste the following code:
PHP Code:
#include <QApplication>
#include <QLabel>
int main(int argcchar *argv[])
{
QApplication app(argcargv);
QLabel *label = new QLabel("Hello World");
label->show();
return 
app.exec();

You will need to pay special attention to the quotes. It needs to be ASCII quotes. If you have an option, select ASCII as the encoding format. Also, make sure there is no extra spacing left at the end of the code. Save it in the HelloWorld folder as HelloWorld.cpp

Now lets compile this.

First, double click the Maemo5 SDK icon to load up an emulator.

Then open up a terminal and login to scratchbox:
Code:
/scratchbox/login
By default,, you should be in the same directory as sbhome, so if you type
Code:
ls
and enter, you should see the following:

Code:
[sbox-FREMANTLE_X86: ~] > ls
HelloWorld  maemo-sdk-rootstrap_5.0_10.2010.19-1_armel.tgz
MyDocs      maemo-sdk-rootstrap_5.0_10.2010.19-1_i386.tgz
[sbox-FREMANTLE_X86: ~] >
Now change to HellowWorld directory:
Code:
cd HelloWorld
Check to see your HellowWorld.cpp file is there:
Code:
[sbox-FREMANTLE_X86: ~] > cd HelloWorld
[sbox-FREMANTLE_X86: ~/HelloWorld] > ls
HelloWorld.cpp
[sbox-FREMANTLE_X86: ~/HelloWorld] >
Now to compile, simply type the following:
Code:
qmake -project
Then:
Code:
qmake
Then finally:
Code:
make
The output should be something like the following:
Code:
[sbox-FREMANTLE_X86: ~/HelloWorld] > qmake -project
QFileInfo::absolutePath: Constructed with empty filename
[sbox-FREMANTLE_X86: ~/HelloWorld] > qmake
[sbox-FREMANTLE_X86: ~/HelloWorld] > make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/targets/FREMANTLE_X86/usr/share/qt4/mkspecs/linux-g++ -I. -I/targets/FREMANTLE_X86/usr/include/QtCore -I/targets/FREMANTLE_X86/usr/include/QtGui -I/targets/FREMANTLE_X86/usr/include -I. -I. -o HelloWorld.o HelloWorld.cpp
g++ -Wl,-O1 -Wl,-rpath,/usr/lib -o HelloWorld HelloWorld.o    -L/usr/lib -lQtGui -L/usr/lib -L/usr/X11R6/lib -lQtCore -lpthread 
[sbox-FREMANTLE_X86: ~/HelloWorld] >
To load our new program up, type the following and hit enter:
Code:
run-standalone.sh ./HelloWorld
Now click on the emulator window, which should show the Hello World program.
 

The Following 16 Users Say Thank You to TheAccountant For This Useful Post: