Saturday 9 March 2013

Building Qt 4.8 Embedded for the Raspberry Pi

These are the steps I went through to build Qt 4.8 for Embedded Linux for the Raspberry Pi.

Build a cross compiler

Follow the instructions on using CrossTool-NG. I used the latest version of CT-NG and chose the GCC, Binutils and Kernel Headers to match the tools on the RasPi. I also had to adjust the compiler support libraries to match, via a process of build, change versions, build, etc. It is also important to enable C++ under language support, as by default only the C compiler is built.
 Once you have built a cross compiler, I strongly recommend testing it by compiling a test program such as:

#include <iostream>
int main(int, char**)
{
  float a = 2.0f * 2.0f;
  std::cout << "Test " << a << std::endl;
  return 0;
}
 Once you have a cross compiler working, edit your ~/.bash_profile file and add the directory containing the tools to your PATH.

Build zLib and OpenSSL

If you want to be able to use SSL sockets, or access https websites, you will need to build zLib and OpenSSL. The instructions below are slightly modified from a post on StackOverflow about this.

  1. Download zLib and OpenSSL source packages and extract them.
  2. Set the following environment variables:
    export CC=`/bin/which arm-unknown-linux-gnueabi-gcc`
    export AR=`/bin/which arm-unknown-linux-gnueabi-ar`
    export RANLIB=`/bin/which arm-unknown-linux-gnueabi-ranlib`
    
  3. Build zLib
    cd zlib-1.2.7
    ./configure --prefix=/opt/raspi
    make
    sudo make install
    
  4. Build OpenSSL
    cd openssl-1.0.1e
    ./Configure linux-elf zlib -L/opt/raspi/lib -I/opt/raspi/include --prefix=/opt/raspi no-asm
    make
    sudo make install
    

Build Qt

Download and extract Qt for Embedded Linux.

Edit the file in  mkspecs/qws/linux-arm-gnueabi-g++/qmake.conf and change the names of the tools to match (mine had built with 'unknown' and not 'none' in the name).

Run the following to build it:

./configure -embedded arm -qt-freetype -prefix /opt/raspi -xplatform qws/linux-arm-gnueabi-g++ -I/opt/raspi/include -L/opt/raspi/lib -no-cups -qt-zlib -qt-libtiff -qt-libpng -qt-libmng -qt-libjpeg -no-javascript-jit -no-qt3support -qt-gfx-linuxfb -qt-gfx-transformed -plugin-gfx-vnc -qt-kbd-tty -qt-kbd-linuxinput -qt-mouse-pc -qt-mouse-linuxinput -openssl

make -j 8
sudo make install

Whilst building I encountered the following problems:
  • Error message:
    fatal error: .pch/release-shared-emb-arm/QtGui: No such file or directory

    This can be fixed by running:
    touch src/gui/.pch/release-shared-emb-arm/QtGui
    
  •  Error message whilst compiling SerializedScriptValue.o This can be fixed by going in to the directory where it is building (src/3rdparty/webkit/Source/WebCore) and re-running the failed call to g++ but with the -O2 flag changed to -O1
Once it has built, you can copy the /opt/raspi directory on to the RasPi, make sure you put it in the same place.

Testing

On the RasPi, before running the demo programs, you need to set the keyboard driver to use with:
export QWS_KEYBOARD=linuxinput

You can then run the demo browser with:
/opt/raspi/demos/browser/browser -qws