玩转树莓派- RaspBerry,Qt5交叉编译移植
时间: 2015-03-20来源:OSCHINA
前景提要
Raspberry Pi (BCM2835): Device Information
Architecture ARMv6
CPU ARM11
RAM 256MB OR 512MB since October 2012 (shared with GPU)
GPU VideoCore IV
OpenGL OpenGL ES 2.0
Multimedia Qt 5.0 (eglfs/QPA)
OpenMax IL 1.1.2 Supported, with OpenGL ES 2.0


Qt 5 port functional state (against Raspbian Wheezy (primary reference platform))
Feature State Additional info
Hardware accelerated cursor Done upstream
Wayland support Done upstream
Hardware decoding of images To Do

Scenegraph tailoring To Do

HardFP support Done Requires v8 patch
Qt Multimedia Webkit integration
Done To Do
Requires gst-omx webgl, tex mapper

开始
首先我们先创建一个目录来存放Qt5的源代码以及交叉编译所需要的所有文件,我选择在当前用户家目录下创建一个叫做“opt”的目录。

1
diveinedu @debian :~$ mkdir ~ /opt


2
diveinedu @debian :~$ cd ~ /opt

然后,下载以下文件:
下载Raspbian Wheezy 镜像 ( 这里 下载 [raspberrypi.org] ):

1
diveinedu @debian :~ /opt $ wget http: //downloads .raspberrypi.org /images/raspbian/2013-02-09-wheezy-raspbian/2013-02-09-wheezy-raspbian .zip


2
diveinedu @debian :~ /opt $unzip 2013-02-09-wheezy-raspbian.zip

下载解压完后挂载镜像:

1
diveinedu @debian :~ /opt $ sudo mkdir /mnt/rasp-pi-rootfs


2
diveinedu@debian:~ /opt $ sudo mount -o loop,offset=62914560 2013-03-09-wheezy-raspbian.img /mnt/rasp-pi-rootfs

我们这不介绍交叉工具链的编译,直接下载针对树莓派优化定制的交叉编译工具链(或者用github上树莓派的工具链 https://github.com/raspberrypi/tools ):

1
diveinedu@debian:~ /opt $ wget http: //blueocean .qmh-project.org /gcc-4 .7-linaro-rpi-gnueabihf.tbz


2
diveinedu@debian:~ /opt $ tar -xf gcc-4.7-linaro-rpi-gnueabihf.tbz

因为上面的交叉编译工具是32位Linux的,如果你所使用的是64位Linux的话,还需要安装32位的运行库软件包:

1
diveinedu@debian:~ /opt $ sudo apt-get install ia32-libs

如果用的是Debian Wheezy的64位系统,上面的行不通,因为Debian Wheezy 64位开启了multiarch-support ,需要执行:

1
diveinedu@debian:~/opt$ sudo apt-get install multiarch-support


2
diveinedu@debian:~/opt$ sudo dpkg --add-architecture i386


3
diveinedu@debian:~/opt$ sudo apt-get update


4
diveinedu@debian:~/opt$ sudo apt-get install ia32-libs


从远程仓库克隆一份cross-compile-tools到本地:

1
diveinedu@debian:~ /opt $ git clone git: //gitorious .org /cross-compile-tools/cross-compile-tools .git

从远程仓库克隆一份Qt5的源码库到本地:

1
diveinedu@debian:~ /opt $ git clone git: //gitorious .org /qt/qt5 .git


2
diveinedu@debian:~ /opt $ cd qt5


3
diveinedu@debian:~ /opt/qt5 $ . /init-repository

最后,把qtjsbackend子项目打补丁让其支持armv6指令集的树莓派:

1
diveinedu@debian:~ /opt/qt5 $ cd ~ /opt/qt5/qtjsbackend


2
diveinedu@debian:~ /opt/qt5 $ git fetch https: //codereview .qt-project.org /p/qt/qtjsbackend refs /changes/56/27256/4 && git cherry-pick FETCH_HEAD

如果有冲突的话就解决冲突的代码。

编译qtbase
现在我们已经准备好了为树莓派交叉编译Qt5所需要的全部资源,在正式编译之前只需要执行一个小脚本来修正一下符号链接和库文件路径设置:

1
diveinedu@debian:~ /opt/qt5 $ cd ~ /opt/cross-compile-tools


2
diveinedu@debian:~ /opt/qt5 $ sudo . /fixQualifiedLibraryPaths /mnt/rasp-pi-rootfs/ ~ /opt/gcc-4 .7-linaro-rpi-gnueabihf /bin/arm-linux-gnueabihf-gcc

进入qt5/qtbase目录执行以下脚本进行配置和编译工作:

1
diveinedu@debian:~ /opt/qt5 $ cd ~ /opt/qt5/qtbase


2
diveinedu@debian:~ /opt/qt5/qtbase $ . /configure -opengl es2 -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=~ /opt/gcc-4 .7-linaro-rpi-gnueabihf /bin/arm-linux-gnueabihf- -sysroot /mnt/rasp-pi-rootfs -opensource -confirm-license -optimized-qmake -reduce-relocations -reduce-exports -release - make libs -prefix /usr/local/qt5pi -no-pch


3
diveinedu@debian:~ /opt/qt5/qtbase $ make -j 4


4
diveinedu@debian:~ /opt/qt5/qtbase $ sudo make install

编译其他模块
执行到这步的时候,你已经有了针对树莓派交叉编译的qmake工具了,你可以一一的去交叉编译Qt5的其他模块了,为里避免模块编译过程中可能 出现的依赖错误,建议按照这个模块顺序去编译: qtimageformats, qtsvg, qtjsbackend, qtscript, qtxmlpatterns, qtdeclarative, qtsensors, qt3d, qtgraphicaleffects,qtjsondb,qtlocation, qtdocgallery.
模块编译相关的类似命令:

1
diveinedu@debian:~ /opt/qt5 $ cd qtimageformats


2
diveinedu@debian:~ /opt/qt5/qtimageformats $ /usr/local/qt5pi/bin/qmake .


3
diveinedu@debian:~ /opt/qt5/qtimageformats $ make -j4


4
diveinedu@debian:~ /opt/qt5/qtimageformats $ sudo make install

把你所需要或者所想编译的模块都按顺序执行编译安装命令后,所有需要的东西都安装在了镜像文件(raspbain wheezy image)里面了。我们接下来就是把他烧到SD卡上去。 SD卡烧写命令:

1
diveinedu@debian:~ /opt/qt5 $ cd ~ /opt/


2
diveinedu@debian:~ /opt $ sync ; sudo umount /mnt/rasp-pi-rootfs


3
diveinedu@debian:~ /opt $ sudo dd bs=1M if =2013-02-09-wheezy-raspbian.img of= /dev/sdc ; sync

提示:/dev/sdc是我使用的SD的设备, 请根据自己的实际情况修改。

到这里,树莓派的Qt5运行库的编译移植过程就Done了。
后续会有例程Demo以及Qt5的QPA机制在树莓派上的eglfs平台插件的特点介绍和传统QtWidget程序在EGLFS环境下遇到的问题和解决分析。

C/C++开发,嵌入式Linux,嵌入式开发, Qt开发, Qt5移植 等, 尽在长沙戴维营教育 ,欢迎前来学习。

科技资讯:

科技学院:

科技百科:

科技书籍:

网站大全:

软件大全:

热门排行