关于树莓交叉编译Qt5

来源:互联网 发布:java过滤器与拦截器 编辑:程序博客网 时间:2024/04/29 06:09

http://qt-project.org/wiki/Qt5OnRaspberryPi

http://qt-project.org/wiki/RaspberryPi_Beginners_guide

---------------------------------------------------------------------------------------------

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 seeRaspberryPi_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 [raspberrypi.org]

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.

  1. unzip 2012-08-16-wheezy-raspbian.zip
  2. sudo dd if=2012-08-16-wheezy-raspbian.img of=/dev/sde bs=1M
  3. 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.

  1. sudo mount -o loop,offset=629145602012-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 [blueocean.qmh-project.org]

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

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.

  1. cd ~/rpi
  2. git clone https://git.gitorious.org/cross-compile-tools/cross-compile-tools.git
  3. 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 viaUSB, 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 fullscreenEGL). Also in the memory_split option give VideoCore 128 MB of memory to be able to run the mostGPU hungryQML 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.

  1. # on the raspberry pi, as user pi (password raspberry)
  2. sudo apt-get update
  3. sudo apt-get install rsync
  4. sudo passwd
  5. # enter root password, I chose raspberry here, same as for the pi user
  6. 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 andQML 2 applications. qtjsbackend needs this not yet integrated patch to work on armv6, so we cherry-pick it:https://codereview.qt-project.org/#change,27256

  1. cd ~/rpi
  2. git clone git://gitorious.org/qt/qtbase.git
  3. git clone git://gitorious.org/qt/qtjsbackend.git
  4. (cd qtjsbackend && git fetch https://codereview.qt-project.org/p/qt/qtjsbackend refs/changes/56/27256/4 && git cherry-pick FETCH_HEAD)
  5. 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 latestHEAD. 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.

  1. cd ~/rpi/qtbase
  2. git checkout 069469b468c482244c5 # if HEAD doesn't build
  3. ./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
  4. # accept the license agreement
  5. make
  6. 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, theSHA-1 of qtjsbackend I tested was e49f760da4b42c96e9f (+ the cherry-pick above), and qtdeclarative was at bf5f97ae626af46742c315.

  1. cd ~/rpi/qtjsbackend
  2. /opt/qt5/bin/qmake
  3. make
  4. sudo make install
  5. cd ~/rpi/qtdeclarative
  6. /opt/qt5/bin/qmake
  7. sudo make
  8. sudo make install

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

  1. cd ~/rpi/qtdeclarative/tools/qmlscene
  2. /opt/qt5/bin/qmake
  3. make
  4. sudo make install
  5. cd ~/rpi/qtdeclarative/examples/demos/samegame/
  6. /opt/qt5/bin/qmake
  7. make
  8. 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.

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

  1. # on the host
  2. ssh pi@172.24.91.127
  1. # on the pi
  2. export LD_LIBRARY_PATH=/opt/qt5/lib/
  3. # to prevent QML 2 animations from running too slow
  4. export QML_FIXED_ANIMATION_STEP=no
  5. /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.


0 0