Qt5 Cross Compile for Raspberry Pi


Qt5 Cross Build for Raspbian

  • Qt 5.4.1
  • Cross host: Debian 8 jessie amd64 (host)
  • Cross target: 2015-02-16-raspbian-wheezy.img loop mounted on /mnt/raspi-rootfs, prepared by QEMU in advance
  • Using Raspbery Pi official cross compiler toolchain
  • Build environment has been deployed to Windows Azure VM
  • Successfull full-compile require about 3GB RAM on host Linux system

Before we start, we need to have a R_Pi image with required package installed;  To do it, either NFS mount for actual running R_Pi or mount on loop device.  Either way works well.  I have been done using NFS mount in the past, which is easy deploy process for application cross build and test.  This time, I have choosen mount on loop device method due to I'd like to deploy environment on Windows Azure for use at outside from my office.  I've created Debian Jessie image on Hyper-V with 32GB disk that is handy size to deploy for Azure VM.

Run Raspberry Pi on host computer using QEMU

See this page for how to run R_Pi on QEMU.  I did not expand image size for this process, but just simply run downloaded 2015-02-16-raspbian-wheezy.img, and run following command;  The packages installed below are required for Qt5 compile.

pi@raspberrypi ~ $ sudo apt-get update
pi@raspberrypi ~ $ sudo apt-get upgrade
pi@raspberrypi ~ $ sudo apt-get install libicu-dev \
                libfontconfig1-dev \
                libudev-dev \
pi@raspberrypi ~ $ sudo shutdown -h now

Obtain cross tools

cd /opt/raspi
git clone https://github.com/raspberrypi/tools
git clone https://gitorious.org/cross-compile-tools/cross-compile-tools.git

Mount Raspberry Pi on host


# assume 2015-02-16-raspbian-wheezy.ims has copied to $prefix/qemu directory
sudo mount -o loop,offset=$((122880*512)) $prefix/qemu/2015-02-16-raspbian-wheezy.img $rootfs

And then, make a symbolic link for qt5 libraries to be installed;

mkdir $destdir/opt/qt5pi
ln -s $destdir/opt/qt5pi $rootfs/opt

Fix broken symbolic link -- 'fixQualifiedLibraryPaths' may not fix symbolic links, see below if it is the case --

cd ../cross-compile-tools
sudo ./fixQualifiedLibraryPaths $rootfs $tooldir/arm-linux-gnueabihf-g++

On my system, the 'file' command is v5.22 that cause a problem due to symbolic link file name does NOT wrapped by "`" and "'" so that script can not extract destination link name at all.  I've done quick dirty fix by modify file command source code as following;

apt-get source file
sudo apt-get build-dep file
cd file-5.22+15
grep "symbolic link to" src/*.c

It shows 3 locations containing "symbolic link to", so modify "%s" to "`%s'" for all 3 locations, then compile it.

Getting Qt5 Source 

At your favorate work directory on the host;

git clone https://gitorious.org/qt/qt5.git
cd qt5

-- or --

wget http://download.qt-project.org/official_releases/qt/5.4/5.4.1/single/qt-everywhere-opensource-src-5.4.1.tar.gz

Configure and Compile Qt5

cd qt5
./configure -opengl es2 \
        -device rasp-pi-g++ \
        -device-option CROSS_COMPILE=$tooldir/arm-linux-gnueabihf- \
        -sysroot $rootfs \
        -opensource -confirm-license \
        -optimized-qmake -reduce-exports -release -nomake tests \
        -prefix /opt/qt5pi -no-pch -skip qttools
make -j4
make install

With the code from git repository (5.4.1+ when this was writing), no file is outputed on /opt/qt5pi but booth host(amd64) binaries and armhf binaries are installed to $rootfs/opt/qqt5pi.  For qt-everywhere-oopensource-src-5.4.1.tar.gz download from qt-project.org has the different behavior, which install host binaries into /opt/qt5pi; and armhf binaries under $rootfs/opt/qt5pi

Dependent packaged on host for Qt5 cross compile;

sudo apt-get install python sudo apt-get install libxcb1 libxcb1-dev libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm4 libxcb-icccm4-dev libxcb-sync-dev libxcb-render-util0 libxcb-render-util0-dev libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-glx0-dev

sudo apt-get install libxkbcommon-dev libudev-dev libwayland-dev libpng12-dev libjpeg62-turbo-dev libmtdev-dev autotools-dev autoconf automake bison flex libasound2-dev libxext-dev x11proto-xext-dev libxcursor-dev libxfixes-dev x11proto-fixes-dev libffi-dev libsm-dev libxcomposite-dev

Install nfs server on Raspberry Pi

This section explain NFS mount, instead of loop-mouint on /mnt.

sudo apt-get install nfs-kernel-server

Create or edit /etc/exports

/      *(rw,sync,no_subtree_check,no_root_squash,insecure)

Security issue:  above setting allows root access to any host, which should be removed after install process completed.

Assume rpcbind is already running.  If not, follow this.






User login