Qt5.4(later)树莓派2 交叉编译环境搭建

费了好大力气,终于把Qt5的交叉环境搞定了,这里记录一下具体的实现过程。google出来的文章都是很老的移植方法,很多博文里面

提供的下载链接均已失效。

1. 准备工具


*  qt-everywhere-opensource-src-5.4.1.tar
*  2015-02-16-raspbian-wheezy.zip
*  cross-compile-tools-master.zip
*  gcc-4.7-linaro-rpi-gnueabihf.tbz

树莓派raspbian和qt5.4的源码都可以非常容易下载到,这里分享交叉编译链的网盘地址:
http://pan.baidu.com/s/1ntILnmT
提取码:x5dz

对于ubuntu14.02的64位系统,要添加32位库的支持,执行:
$ sudo apt-get install ia32-libs
如果你的系统比较老一点(题主的是Ubuntu12.02),z执行如下:
$ sudo apt-get install g++-multilib ia32-libs


2. 预定义路径和文件名


PREFIX= /usr/local/qt5
ROOTFS_MOUNT=/mnt/rasp-pi-rootfs
WORKDIR=~/qt5rpi

$ sudo mkdir $PREFIX

$ sudo mkdir $ROOTFS_MOUNT


3. 解压他们



为了方便说明,先下面的压缩文件均放置在$WORKDIR中

$ sudo tar xvf qt-everywhere-opensource-src-5.tar
$ sudo unzip 2015-02-16-raspbian-wheezy.zip
$ sudo unzip cross-compile-tools-master.zip

$ sudo tar -xjf gcc-4.7-linaro-rpi-gnueabihf.tbz


4. 挂载下载好的最新Raspbian


$ sudo mount -o loop,offset=62914560 2015-02-16-wheezy-raspbian.img $ROOTFS_MOUNT
上述指令中,有两点需要注意容易出错:

* loop,offset 之间,不能出现空格
* offset该等于多少?执行命令
$sudo fdisk -l 2015-02-16-raspbian-wheezy.img
执行结果:
Device Boot       Start       End        Blocks    Id   System
2015-02-16-raspbian-wheezy.img1             8192       122879     57344     c   W95 FAT32 (LBA)
2015-02-16-raspbian-wheezy.img2             122880     6399999    3138560   83   Linux

offset=(512* 122880) ,这样就不会出错了。


5. 使用cross-compile-tools进行目录配置


cross-compile-tools-master.zip目前大部分对Qt5进行移植的教程都是从:
git clone git://gitorious.org/cross-compile-tools/cross-compile-tools.git
这个地方下载,但是这个网站已经蹦掉了,有热心的老大重新把他上传到了github上,新的地址为:
https://github.com/shahriman/cross-compile-tools
执行如下指令:
$ cd cross-compile-tools-master

$ sudo ./fixQualifiedLibraryPaths $ROOTFS_MOUNT $WORKDIR/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-gcc


6. 编译qtbase


$ cd $WORKDIR/qt-everywhere-opensource-src-5/qtbase
$ ./configure -opengl es2 \
        -device rasp-pi-g++ \
        -device-option CROSS_COMPILE=$WORKDIR/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf- \
        -sysroot $ROOTFS_MOUNT \
        -opensource -confirm-license \
        -optimized-qmake -reduce-exports -release -nomake tests \
        -prefix $PREFIX -no-pch -skip qttools
$ sudo make -j4
$ sudo make install

等待编译完成,需要一定时间



7. 编译其他的qt模块


用一个小的shell脚本:
cd $WORKDIR/qt-everywhere-opensource-src-5
for MODULE in qtimageformats qtsvg qtscript qtxmlpatterns qtdeclarative qtsensors qtgraphicaleffects qtlocation qtserialport qttools qtquick1 qtquickcontrols
do
 cd $MODULE
 $PREFIX/bin/qmake .
 make -j4
 sudo make install
 cd ..
done



8. 配置QtCreator


这个不是本文的范畴,编译都没问题了,后面的资料好查找。
如上步骤可以组成一个完整的shell脚本,请自行实验

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值