Qt5 on RaspberryPi: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
(Marked as outdated)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
h1. Simplified guide for getting Qt 5 built and installed on the raspberry pi
{{Outdated|reason=Old toolchain. Many broken links.}}
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}


= Simplified guide for getting Qt 5 built and installed on the raspberry pi =
== Overview ==
== Overview ==


Line 9: Line 11:
== Preparing the sysroot and getting the toolchain ==
== Preparing the sysroot and getting the toolchain ==


Download the Debian Wheezy image from here and flash it on your device: "raspberrypi.org download page":http://www.raspberrypi.org/downloads
Download the Debian Wheezy image from here and flash it on your device: [http://www.raspberrypi.org/downloads raspberrypi.org download page]


The instructions here are tested with the 2012-08-16-wheezy-raspbian image, but should work with 2012-07-15-wheezy-raspbian as well.
The instructions here are tested with the 2012-08-16-wheezy-raspbian image, but should work with 2012-07-15-wheezy-raspbian as well.


Replace /dev/sde with the location of your SD card as reported by "sudo fdisk -l". Note that this will overwrite any previous contents on the SD card.
Replace /dev/sde with the location of your SD card as reported by "sudo fdisk -l". Note that this will overwrite any previous contents on the SD card.


<code><br />unzip 2012-08-16-wheezy-raspbian.zip<br />sudo dd if=2012-08-16-wheezy-raspbian.img of=/dev/sde bs=1M<br />sudo eject /dev/sde<br /></code>
<code>
unzip 2012-08-16-wheezy-raspbian.zip
sudo dd if=2012-08-16-wheezy-raspbian.img of=/dev/sde bs=1M
sudo eject /dev/sde
</code>


We also mount the wheezy image at /mnt/rasp-pi-rootfs for use as a sysroot during cross compilation of Qt 5. The offset 62914560 is computed by running &quot;sudo fdisk -l&amp;quot; on the .img file, and multiplying the sector size 512 bytes with the start of the Linux partition at sector 122880. It's the same for 2012-07-15-wheezy-raspbian. Remember to re-mount the image in case you reboot as well, otherwise a lot of confusion might ensue.
We also mount the wheezy image at /mnt/rasp-pi-rootfs for use as a sysroot during cross compilation of Qt 5. The offset 62914560 is computed by running "sudo fdisk -l" on the .img file, and multiplying the sector size 512 bytes with the start of the Linux partition at sector 122880. It's the same for 2012-07-15-wheezy-raspbian. Remember to re-mount the image in case you reboot as well, otherwise a lot of confusion might ensue.


<code><br />sudo mount -o loop,offset=62914560 2012-08-16-wheezy-raspbian.img /mnt/rasp-pi-rootfs<br /></code>
<code>
sudo mount -o loop,offset=62914560 2012-08-16-wheezy-raspbian.img /mnt/rasp-pi-rootfs
</code>


Get and extract the Linaro toolchain graciously built and provided by Donald: &quot;gcc-4.7-linaro&amp;quot;:http://blueocean.qmh-project.org/gcc-4.7-linaro-rpi-gnueabihf.tbz
Get and extract the Linaro toolchain graciously built and provided by Donald: [http://blueocean.qmh-project.org/gcc-4.7-linaro-rpi-gnueabihf.tbz gcc-4.7-linaro]


<code><br />mkdir <sub>/rpi<br />cd</sub>/rpi<br />wget http://blueocean.qmh-project.org/gcc-4.7-linaro-rpi-gnueabihf.tbz<br />tar -xjf gcc-4.7-linaro-rpi-gnueabihf.tbz<br /></code><br />The main site seem's down, there is a mirror on http://swap.tsmt.eu/gcc-4.7-linaro-rpi-gnueabihf.tbz
<code>
mkdir ~/rpi
cd~/rpi
wget http://blueocean.qmh-project.org/gcc-4.7-linaro-rpi-gnueabihf.tbz
tar -xjf gcc-4.7-linaro-rpi-gnueabihf.tbz
</code>
The main site is down. There was a mirror on http://swap.tsmt.eu/gcc-4.7-linaro-rpi-gnueabihf.tbz but this is down, too.


Get and run the fixQualifiedLibraryPaths script from cross-compile-tools in order to fix broken symlinks in the image.
Get and run the fixQualifiedLibraryPaths script from cross-compile-tools in order to fix broken symlinks in the image.


<code><br />cd <sub>/rpi<br />git clone https://git.gitorious.org/cross-compile-tools/cross-compile-tools.git<br />cross-compile-tools/fixQualifiedLibraryPaths /mnt/rasp-pi-rootfs</sub>/rpi/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-gcc<br /></code>
<code>
cd ~/rpi
git clone https://git.gitorious.org/cross-compile-tools/cross-compile-tools.git
cross-compile-tools/fixQualifiedLibraryPaths /mnt/rasp-pi-rootfs~/rpi/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-gcc
</code>


== Preparing the Raspberry Pi ==
== Preparing the Raspberry Pi ==
Line 35: Line 53:
Also install rsync which we will later use to copy over the Qt libraries and binaries, and set the root password to enable rsync'ing to the root user.
Also install rsync which we will later use to copy over the Qt libraries and binaries, and set the root password to enable rsync'ing to the root user.


<code><br /># on the raspberry pi, as user pi (password raspberry)<br />sudo apt-get update<br />sudo apt-get install rsync<br />sudo passwd<br /># enter root password, I chose raspberry here, same as for the pi user<br />sudo reboot<br /></code>
<code>
# on the raspberry pi, as user pi (password raspberry)
sudo apt-get update
sudo apt-get install rsync
sudo passwd
# enter root password, I chose raspberry here, same as for the pi user
sudo reboot
</code>


After the raspberry has rebooted it will tell you its IP address above the login prompt. Keep track of this IP address for later.
After the raspberry has rebooted it will tell you its IP address above the login prompt. Keep track of this IP address for later.
Line 43: Line 68:
First we clone the Qt source packages we're interested in to be able to run qmlscene and QML 2 applications. qtjsbackend needs this not yet integrated patch to work on armv6, so we cherry-pick it: https://codereview.qt.io/#change,27256
First we clone the Qt source packages we're interested in to be able to run qmlscene and QML 2 applications. qtjsbackend needs this not yet integrated patch to work on armv6, so we cherry-pick it: https://codereview.qt.io/#change,27256


<code><br />cd <sub>/rpi<br />git clone git://gitorious.org/qt/qtbase.git<br />git clone git://gitorious.org/qt/qtjsbackend.git<br />(cd qtjsbackend &amp;&amp; git fetch https://codereview.qt.io/p/qt/qtjsbackend refs/changes/56/27256/4 &amp;&amp; git cherry-pick FETCH_HEAD)<br />git clone git://gitorious.org/qt/qtdeclarative.git<br /></code>
<code>
<br />Next we configure and build qtbase. I've chosen the prefix /opt/qt5, which is where the qt libraries etc will end up on the device image. You might need to sync qtbase back to change 069469b468c482244c5, since I experienced build issues with the latest HEAD. If you get any build failures it's a good idea to do &quot;git clean <s>dxf&amp;quot; in qtbase before trying again, to remove any by-products of the failed build. Note that this will erase any local changes you've made to qtbase, so use with caution.
cd ~/rpi
<br /><code><br />cd <sub>/rpi/qtbase<br />git checkout 069469b468c482244c5 # if HEAD doesn't build<br />./configure -prefix /opt/qt5 -release -device linux-rasp-pi-g++ -make libs -device-option CROSS_COMPILE=</sub>/rpi/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf</s> -sysroot /mnt/rasp-pi-rootfs<br /># accept the license agreement<br />make<br />sudo make install<br /></code>
git clone git://gitorious.org/qt/qtbase.git
<br />We're ready to build and install the other modules now, using the qmake built together with qtbase. Since it's a host tool it's installed in /opt/qt5/bin outside of the sysroot at /mnt/rasp-pi-rootfs.
git clone git://gitorious.org/qt/qtjsbackend.git
<br />Due to a build error I encountered with the latest qtdeclarative I had to use &quot;sudo make&amp;quot;. For reference, the SHA-1 of qtjsbackend I tested was e49f760da4b42c96e9f (+ the cherry-pick above), and qtdeclarative was at bf5f97ae626af46742c315.
(cd qtjsbackend && git fetch https://codereview.qt.io/p/qt/qtjsbackend refs/changes/56/27256/4 && git cherry-pick FETCH_HEAD)
<br /><code><br />cd</sub>/rpi/qtjsbackend<br />/opt/qt5/bin/qmake<br />make<br />sudo make install<br />cd <sub>/rpi/qtdeclarative<br />/opt/qt5/bin/qmake<br />sudo make<br />sudo make install<br /></code>
git clone git://gitorious.org/qt/qtdeclarative.git
<br />Since qmlscene doesn't get built automatically, we do it manually. We also build samegame to have a QML 2 example to test.
</code>
<br /><code><br />cd</sub>/rpi/qtdeclarative/tools/qmlscene<br />/opt/qt5/bin/qmake<br />make<br />sudo make install<br />cd ~/rpi/qtdeclarative/examples/demos/samegame/<br />/opt/qt5/bin/qmake<br />make<br />sudo make install<br /></code>
 
Next we configure and build qtbase. I've chosen the prefix /opt/qt5, which is where the qt libraries etc will end up on the device image. You might need to sync qtbase back to change 069469b468c482244c5, since I experienced build issues with the latest HEAD. If you get any build failures it's a good idea to do "git clean -dxf" in qtbase before trying again, to remove any by-products of the failed build. Note that this will erase any local changes you've made to qtbase, so use with caution.
 
<code>
cd ~/rpi/qtbase
git checkout 069469b468c482244c5 # if HEAD doesn't build
./configure -prefix /opt/qt5 -release -device linux-rasp-pi-g++ -make libs -device-option CROSS_COMPILE=~/rpi/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf- -sysroot /mnt/rasp-pi-rootfs
# accept the license agreement
make
sudo make install
</code>
 
We're ready to build and install the other modules now, using the qmake built together with qtbase. Since it's a host tool it's installed in /opt/qt5/bin outside of the sysroot at /mnt/rasp-pi-rootfs.
 
Due to a build error I encountered with the latest qtdeclarative I had to use "sudo make". For reference, the SHA-1 of qtjsbackend I tested was e49f760da4b42c96e9f (+ the cherry-pick above), and qtdeclarative was at bf5f97ae626af46742c315.
 
<code>
cd~/rpi/qtjsbackend
/opt/qt5/bin/qmake
make
sudo make install
cd ~/rpi/qtdeclarative
/opt/qt5/bin/qmake
sudo make
sudo make install
</code>
 
Since qmlscene doesn't get built automatically, we do it manually. We also build samegame to have a QML 2 example to test.
 
<code>
cd~/rpi/qtdeclarative/tools/qmlscene
/opt/qt5/bin/qmake
make
sudo make install
cd ~/rpi/qtdeclarative/examples/demos/samegame/
/opt/qt5/bin/qmake
make
sudo make install
</code>


== Getting our /opt/qt5 onto the device ==
== Getting our /opt/qt5 onto the device ==
Line 56: Line 119:
Now it's just a matter of rsync'ing our /opt/qt5 to the device. Exchange the IP address with your own raspberry pi's IP address as noted earlier (displayed right after the pi's boot, above the login prompt). Note the trailing slash on the source directory, without it you'll end up with /opt/qt5/qt5 on the device.
Now it's just a matter of rsync'ing our /opt/qt5 to the device. Exchange the IP address with your own raspberry pi's IP address as noted earlier (displayed right after the pi's boot, above the login prompt). Note the trailing slash on the source directory, without it you'll end up with /opt/qt5/qt5 on the device.


<code><br />rsync -av /mnt/rasp-pi-rootfs/opt/qt5/ root</code>172.24.91.127:/opt/qt5/<br /><code>
<code>
rsync -av /mnt/rasp-pi-rootfs/opt/qt5/ root@172.24.91.127:/opt/qt5/
</code>


== Trying out stuff ==
== Trying out stuff ==
Line 62: Line 127:
ssh into the device as the pi user, and run an example.
ssh into the device as the pi user, and run an example.


</code><br /># on the host<br />ssh pi<code>172.24.91.127<br /></code>
<code>
# on the host
ssh pi@172.24.91.127
</code>


<code><br /># on the pi<br />export LD_LIBRARY_PATH=/opt/qt5/lib/<br /># to prevent QML 2 animations from running too slow<br />export QML_FIXED_ANIMATION_STEP=no<br />/opt/qt5/examples/qtdeclarative/demos/samegame/samegame<br /></code>
<code>
# on the pi
export LD_LIBRARY_PATH=/opt/qt5/lib/
# to prevent QML 2 animations from running too slow
export QML_FIXED_ANIMATION_STEP=no
/opt/qt5/examples/qtdeclarative/demos/samegame/samegame
</code>


samegame should be running now, and you can interact with it if you have a mouse connected to the raspberry pi.
samegame should be running now, and you can interact with it if you have a mouse connected to the raspberry pi.

Latest revision as of 02:12, 24 March 2016

IMPORTANT: The content of this page is outdated. Reason: Old toolchain. Many broken links.
If you have checked or updated this page and found the content to be suitable, please remove this notice.
This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine.
Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean.

Simplified guide for getting Qt 5 built and installed on the raspberry pi

Overview

Since the instructions at the RaspberryPi wiki-page can be a bit confusing I've created this step-by-step guide to document what works for me. I'm using Ubuntu 12.04, but I don't see why the instructions wouldn't work on older / other distros.

Update: I was made aware that another similar guide already existed, and it looks to be more complete than this guide, please see RaspberryPi_Beginners_guide

Preparing the sysroot and getting the toolchain

Download the Debian Wheezy image from here and flash it on your device: raspberrypi.org download page

The instructions here are tested with the 2012-08-16-wheezy-raspbian image, but should work with 2012-07-15-wheezy-raspbian as well.

Replace /dev/sde with the location of your SD card as reported by "sudo fdisk -l". Note that this will overwrite any previous contents on the SD card.

unzip 2012-08-16-wheezy-raspbian.zip
sudo dd if=2012-08-16-wheezy-raspbian.img of=/dev/sde bs=1M
sudo eject /dev/sde

We also mount the wheezy image at /mnt/rasp-pi-rootfs for use as a sysroot during cross compilation of Qt 5. The offset 62914560 is computed by running "sudo fdisk -l" on the .img file, and multiplying the sector size 512 bytes with the start of the Linux partition at sector 122880. It's the same for 2012-07-15-wheezy-raspbian. Remember to re-mount the image in case you reboot as well, otherwise a lot of confusion might ensue.

sudo mount -o loop,offset=62914560 2012-08-16-wheezy-raspbian.img /mnt/rasp-pi-rootfs

Get and extract the Linaro toolchain graciously built and provided by Donald: gcc-4.7-linaro

mkdir ~/rpi
cd~/rpi
wget http://blueocean.qmh-project.org/gcc-4.7-linaro-rpi-gnueabihf.tbz
tar -xjf gcc-4.7-linaro-rpi-gnueabihf.tbz

The main site is down. There was a mirror on http://swap.tsmt.eu/gcc-4.7-linaro-rpi-gnueabihf.tbz but this is down, too.

Get and run the fixQualifiedLibraryPaths script from cross-compile-tools in order to fix broken symlinks in the image.

cd ~/rpi
git clone https://git.gitorious.org/cross-compile-tools/cross-compile-tools.git
cross-compile-tools/fixQualifiedLibraryPaths /mnt/rasp-pi-rootfs~/rpi/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-gcc

Preparing the Raspberry Pi

The first time you boot the Raspberry Pi you get a configuration menu. Otherwise, manually run raspi-config. Make sure a keyboard is connected via USB, and that the raspberry pi is connected to your local area network via a network cable. From this menu you'll want to run the expand_rootfs option, enable ssh server, set the boot_behaviour to no to prevent X from starting (since we'll be running Qt directly on top of fullscreen EGL). Also in the memory_split option give VideoCore 128 MB of memory to be able to run the most GPU hungry QML 2 applications.

Also install rsync which we will later use to copy over the Qt libraries and binaries, and set the root password to enable rsync'ing to the root user.

# on the raspberry pi, as user pi (password raspberry)
sudo apt-get update
sudo apt-get install rsync
sudo passwd
# enter root password, I chose raspberry here, same as for the pi user
sudo reboot

After the raspberry has rebooted it will tell you its IP address above the login prompt. Keep track of this IP address for later.

Building qtbase, qtjsbackend, and qtdeclarative

First we clone the Qt source packages we're interested in to be able to run qmlscene and QML 2 applications. qtjsbackend needs this not yet integrated patch to work on armv6, so we cherry-pick it: https://codereview.qt.io/#change,27256

cd ~/rpi
git clone git://gitorious.org/qt/qtbase.git
git clone git://gitorious.org/qt/qtjsbackend.git
(cd qtjsbackend && git fetch https://codereview.qt.io/p/qt/qtjsbackend refs/changes/56/27256/4 && git cherry-pick FETCH_HEAD)
git clone git://gitorious.org/qt/qtdeclarative.git

Next we configure and build qtbase. I've chosen the prefix /opt/qt5, which is where the qt libraries etc will end up on the device image. You might need to sync qtbase back to change 069469b468c482244c5, since I experienced build issues with the latest HEAD. If you get any build failures it's a good idea to do "git clean -dxf" in qtbase before trying again, to remove any by-products of the failed build. Note that this will erase any local changes you've made to qtbase, so use with caution.

cd ~/rpi/qtbase
git checkout 069469b468c482244c5 # if HEAD doesn't build
./configure -prefix /opt/qt5 -release -device linux-rasp-pi-g++ -make libs -device-option CROSS_COMPILE=~/rpi/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf- -sysroot /mnt/rasp-pi-rootfs
# accept the license agreement
make
sudo make install

We're ready to build and install the other modules now, using the qmake built together with qtbase. Since it's a host tool it's installed in /opt/qt5/bin outside of the sysroot at /mnt/rasp-pi-rootfs.

Due to a build error I encountered with the latest qtdeclarative I had to use "sudo make". For reference, the SHA-1 of qtjsbackend I tested was e49f760da4b42c96e9f (+ the cherry-pick above), and qtdeclarative was at bf5f97ae626af46742c315.

cd~/rpi/qtjsbackend
/opt/qt5/bin/qmake
make
sudo make install
cd ~/rpi/qtdeclarative
/opt/qt5/bin/qmake
sudo make
sudo make install

Since qmlscene doesn't get built automatically, we do it manually. We also build samegame to have a QML 2 example to test.

cd~/rpi/qtdeclarative/tools/qmlscene
/opt/qt5/bin/qmake
make
sudo make install
cd ~/rpi/qtdeclarative/examples/demos/samegame/
/opt/qt5/bin/qmake
make
sudo make install

Getting our /opt/qt5 onto the device

Now it's just a matter of rsync'ing our /opt/qt5 to the device. Exchange the IP address with your own raspberry pi's IP address as noted earlier (displayed right after the pi's boot, above the login prompt). Note the trailing slash on the source directory, without it you'll end up with /opt/qt5/qt5 on the device.

rsync -av /mnt/rasp-pi-rootfs/opt/qt5/ root@172.24.91.127:/opt/qt5/

Trying out stuff

ssh into the device as the pi user, and run an example.

# on the host
ssh pi@172.24.91.127
# on the pi
export LD_LIBRARY_PATH=/opt/qt5/lib/
# to prevent QML 2 animations from running too slow
export QML_FIXED_ANIMATION_STEP=no
/opt/qt5/examples/qtdeclarative/demos/samegame/samegame

samegame should be running now, and you can interact with it if you have a mouse connected to the raspberry pi.