Qt5.4(later)樹莓派2 交叉編譯環境搭建
阿新 • • 發佈:2019-01-03
費了好大力氣,終於把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. 預定義路徑和檔名
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指令碼,請自行實驗