Qt5 on RaspberryPi: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
=Simplified guide for getting Qt 5 built and installed on the raspberry pi=
h1. Simplified guide for getting Qt 5 built and installed on the raspberry pi


==Overview==
== 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.
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|RaspberryPi_Beginners_guide]]
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==
== Preparing the sysroot and getting the toolchain ==


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


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.


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 />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>


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] ''[blueocean.qmh-project.org]''
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.


The main site seem’s down, there is a mirror on http://swap.tsmt.eu/gcc-4.7-linaro-rpi-gnueabihf.tbz
<code><br />sudo mount -o loop,offset=62914560 2012-08-16-wheezy-raspbian.img /mnt/rasp-pi-rootfs<br /></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
 
<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


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.


==Preparing the Raspberry Pi==
<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>
 
== 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.


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 <span class="caps">USB</span>, 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 <span class="caps">EGL</span>). Also in the memory_split option give VideoCore 128 MB of memory to be able to run the most <span class="caps">GPU</span> hungry <span class="caps">QML</span> 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.


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>


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.


==Building qtbase, qtjsbackend, and qtdeclarative==
== Building qtbase, qtjsbackend, and qtdeclarative ==


First we clone the Qt source packages we’re interested in to be able to run qmlscene and <span class="caps">QML</span> 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


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 <span class="caps">HEAD</span>. 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><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>
<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.
<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>
<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.
<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.
<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>
<br />Since qmlscene doesn't get built automatically, we do it manually. We also build samegame to have a QML 2 example to test.
<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>


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.
== Getting our /opt/qt5 onto the device ==


Due to a build error I encountered with the latest qtdeclarative I had to use “sudo make”. For reference, the <span class="caps">SHA</span>-1 of qtjsbackend I tested was e49f760da4b42c96e9f (+ the cherry-pick above), and qtdeclarative was at bf5f97ae626af46742c315.
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.


Since qmlscene doesn’t get built automatically, we do it manually. We also build samegame to have a <span class="caps">QML</span> 2 example to test.
<code><br />rsync -av /mnt/rasp-pi-rootfs/opt/qt5/ root</code>172.24.91.127:/opt/qt5/<br /><code>


==Getting our /opt/qt5 onto the device==
== Trying out stuff ==


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.
ssh into the device as the pi user, and run an example.


==Trying out stuff==
</code><br /># on the host<br />ssh pi<code>172.24.91.127<br /></code>


ssh into the device as the pi user, and run an example.
<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>


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.

Revision as of 14:27, 23 February 2015

h1. 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&quot;:http://www.raspberrypi.org/downloads

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&quot;. Note that this will overwrite any previous contents on the SD card.

<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 />

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&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.

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

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

<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 />


The main site seem's down, there is a mirror on http://swap.tsmt.eu/gcc-4.7-linaro-rpi-gnueabihf.tbz

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

<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 />

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.

<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 />

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

<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 />


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&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.


<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 />


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&quot;. For reference, the SHA-1 of qtjsbackend I tested was e49f760da4b42c96e9f (+ the cherry-pick above), and qtdeclarative was at bf5f97ae626af46742c315.


<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 />


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


<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 />

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.

<br />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<br />
<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 />

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