Cross-Compiling

Compiling ARM on Intel x86

There is another howto available at: dudu.dyn.2-h.org/nist/qt-notes.php

This howto explains howto compile software for ARM devices on a Intel x86 machine.

 

1. Download an Install OPIE SDK

  • Download the SDK from opie.handhelds.org
  • Extract the contents to /opt
  • The package includes the C header files and the precompiled libraries for QtEmbedded and OPIE for both x86 and ARM architectures.

 

2. Install cross-compiler (GCC 2.95 based, from the Open Zaurus team)

First you need to download and unpack the latest GCC 2.95 based toolchain.

cd /tmp
wget www.openzaurus.org/official/toolchain/cross-2.95.3.tar.bz2
tar jvxf cross-2.95.3.tar.bz2


Now the compiler needs to be installed in /usr/local/arm and the environment variables need to be set:

mkdir /usr/local/arm
cp -a 2.95.3 /usr/local/arm
export PATH=/usr/local/arm/2.95.3/bin:$PATH

 

3. Install the additional needed ARM libraries

Download the ARM headers and libraries from the Debian package pool.

wget -N
 http://http.us.debian.org/debian/pool/main/libj/libjpeg6b/{libjpeg62,libjpeg62-dev}_6b-5_arm.deb
 http://http.us.debian.org/debian/pool/main/f/freetype/{libfreetype6,libfreetype6-dev}_2.0.9-1_arm.deb
 http://http.us.debian.org/debian/pool/main/z/zlib/{zlib1g,zlib1g-dev}_1.1.4-1.0woody0_arm.deb
 http://http.us.debian.org/debian/pool/main/libp/libpcap/{libpcap0.7,libpcap0.7-dev}_0.7.2-7_arm.deb
 http://http.us.debian.org/debian/pool/main/libp/libpng3/{libpng3,libpng-dev}_1.2.1-1.1.woody.9_arm.deb
 http://http.us.debian.org/debian/pool/main/b/bluez-libs/{libbluetooth1,libbluetooth1-dev}_2.11-1_arm.deb
 http://http.us.debian.org/debian/pool/main/g/gcc-3.0/libgcc1_3.0.4-7_arm.deb
 http://http.us.debian.org/debian/pool/main/p/pcsc-lite/{libpcsclite1,libpcsclite-dev}_1.2.9-beta6-1_arm.deb
 http://http.us.debian.org/debian/pool/main/f/flex/flex_2.5.4a-24_arm.deb
 http://dudu.dyn.2-h.org/nist/libpam0g-dev_0.76-9_arm_for_Opie.tgz

 

4. Unpack the packages

mkdir libjpeg62 && dpkg-deb -x libjpeg62_6b-5_arm.deb libjpeg62 && dpkg-deb -x libjpeg62-dev_6b-5_arm.deb libjpeg62 && mkdir libfreetype6 && dpkg-deb -x libfreetype6_2.0.9-1_arm.deb libfreetype6 && dpkg-deb -x libfreetype6-dev_2.0.9-1_arm.deb libfreetype6 && mkdir zlib1g && dpkg-deb -x zlib1g_1.1.4-1.0woody0_arm.deb zlib1g && dpkg-deb -x zlib1g-dev_1.1.4-1.0woody0_arm.deb zlib1g && mkdir libpcap0.7 && dpkg-deb -x libpcap0.7_0.7.2-7_arm.deb libpcap0.7 && dpkg-deb -x libpcap0.7-dev_0.7.2-7_arm.deb libpcap0.7 && mkdir libpng3 && dpkg-deb -x libpng3_1.2.1-1.1.woody.9_arm.deb libpng3 && dpkg-deb -x libpng-dev_1.2.1-1.1.woody.9_arm.deb libpng3 && mkdir libbluetooth1 && dpkg-deb -x libbluetooth1_2.11-1_arm.deb libbluetooth1 && dpkg-deb -x libbluetooth1-dev_2.11-1_arm.deb libbluetooth1 && mkdir libgcc1 && dpkg-deb -x libgcc1_3.0.4-7_arm.deb libgcc1 && mkdir libpcsclite1 && dpkg-deb -x libpcsclite1_1.2.9-beta6-1_arm.deb libpcsclite1 && dpkg-deb -x libpcsclite-dev_1.2.9-beta6-1_arm.deb libpcsclite1 && mkdir flex && dpkg-deb -x flex_2.5.4a-24_arm.deb flex && tar xzf libpam0g-dev_0.76-9_arm_for_Opie.tgz

 

5. Copy the new header files and libraries in the right directories

find libjpeg62 libfreetype6 zlib1g libpcap0.7 libpng3 libbluetooth1 libgcc1 libpcsclite1 flex -path '*/include/*' -maxdepth 3 -exec cp -R {} /usr/local/arm/2.95.3/arm-linux/include \;
find libjpeg62 libfreetype6 zlib1g libpcap0.7 libpng3 libbluetooth1 libgcc1 libpcsclite1 flex -path '*/lib/*' -maxdepth 3 -exec cp -R --no-dereference {} /usr/local/arm/2.95.3/arm-linux/lib \;

 

6. Setup the environment

Two files are created for the different platforms to configure the environment files. This is done with one of the two commands below then:

source ~/opie_env/x86
source ~/opie_env/arm

~/opie_env/x86

# opie sdk for x86
export QTDIR=/opt/OpieSdk/opie/x86/qt-2.3.7
export OPIEDIR=/opt/OpieSdk/opie/x86/sdk
export LD_LIBRARY_PATH=$QTDIR/lib:$OPIEDIR/lib
export PATH=$QTDIR/bin:$OPIEDIR/bin:$PATH
export QMAKESPEC=$OPIEDIR/mkspecs/qws/linux-generic-g+

~/opie_env/arm

# opie sdk for arm
export QTDIR=/opt/OpieSdk/opie/arm/qt-2.3.7
export OPIEDIR=/opt/OpieSdk/opie/arm/sdk
export LD_LIBRARY_PATH=$QTDIR/lib:$OPIEDIR/lib
export PATH=$QTDIR/bin:$OPIEDIR/bin:$PATH
export QMAKESPEC=$OPIEDIR/mkspecs/qws/linux-arm-g++

 

7. Create a new OPIE project

Open the OPIE SDK an add a new project.

 

 

8. Set up the Layout and Design for the Application

Runthe Qt designer and open the file yourAppsName.ui. Now you can do some clicks to get the application going. Note: With every "make" the fwo files yourAppsNameBase.cpp / yourAppsNameBase.h are created again. These are create automatically from the yourAppsName.ui file. That's why you should not edit these files manually.

 

9. Prepare for the first "make"

Open the file yourAppsName.pro and create a new config section.

If you want to compile for x86, you need this config:

nameOfConfig {
INCLUDEPATH += /usr/include
DEPENDPATH += /usr/include
LIBS += -lbluetooth --if you want to compile with the bluetooth libs
}

And for ARM you need this:

nameOfConfig {
INCLUDEPATH += /usr/local/arm/2.95.3/arm-linux/include
DEPENDPATH += /usr/local/arm/2.95.3/arm-linux/include
LIBS += -lbluetooth
}

After that the new config section will be add in the config line (see below) and will be activated then.

CONFIG = qt qtopia warn_on release zecke-libqpe zecke-libopie nameOfConfig


Now one of the both environment files need to be loaded so qmake is generating a correct makefile.

source host_target
source arm_target

 

10. Create a makefile

Now you can create a makefile from the edited .pro file. This step is done for you by qmake (available at www.opie.handhelds.org)

qmake -o Makefile yourAppsName.pro

If the error occurs "Removing of 'libyourAppName.so*' not possible" a simple

touch libyourAppName.so

does the trick.

 

11. Compiling the application

make

 

12. What do to if you want to change the target platform?

  • First run "make clean" to remove all compiled files.
  • Load "~/opie_env/x86" or "~/opie_env/arm"
  • Edit the "yourAppsName.pro" file and change the INCLUDEPATH and DEPENDPATH.
  • Run:
qmake -o Makefile yourAppsName.pro
make