出处 : http://blog.diveinedu.net/?p=433



树莓派上Qt5交叉编译移植新手指南

发表于作者 大茶园丁暂无评论 ↓

Raspberry Pi (BCM2835): Device InformationArchitectureARMv6CPUARM11RAM256MB OR 512MB since October 2012 (shared with GPU)GPUVideoCore IVOpenGLOpenGL ES 2.0MultimediaOpenMax IL 1.1.2Qt 5.0 (eglfs/QPA)Supported, with OpenGL ES 2.0


Qt 5 port functional state (against Raspbian Wheezy (primary reference platform))FeatureStateAdditional infoHardware accelerated cursorDoneupstreamWayland supportDoneupstreamHardware decoding of p_w_picpathsTo DoScenegraph tailoringTo DoHardFP supportDoneRequires v8 patchQt MultimediaDoneRequires gst-omxWebkit integrationTo Dowebgl, tex mapper


  • 开始

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

    1diveinedu@debian:~$ mkdir  ~/opt

    2diveinedu@debian:~$ cd  ~/opt

    然后,下载以下文件:

    下载Raspbian Wheezy 镜像  (这里下载 [raspberrypi.org]):

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

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

    下载解压完后挂载镜像:

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

    2diveinedu@debian:~/opt$   cd qt5

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

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

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

    2diveinedu@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所需要的全部资源,在正式编译之前只需要执行一个小脚本来修正一下符号链接和库文件路径设置:

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

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

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

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

    2diveinedu@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

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

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


  • 编译其他模块

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

    模块编译相关的类似命令:

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

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

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

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

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

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

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

    3diveinedu@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环境下遇到的问题和解决分析。