交叉编译树莓派QT5.10

交叉编译树莓派QT5.10

环境准备

  • Raspberry PI3
  • System image: 2017-11-29-raspbian-stretch.zip
  • Qt Version: Qt5.10.0
  • Host: Ubuntu 14.04
  • Cross Compiler: gcc-linaro-4.9-2015.02-3-x86_64_arm-linux-gnueabihf

挂载镜像

挂载镜像更稳健系统到 /mnt

$ unzip 2017-11-29-raspbian-stretch.zip
Archive:  2017-11-29-raspbian-stretch.zip
  inflating: 2017-11-29-raspbian-stretch.img

$ sudo fdisk -l 2017-11-29-raspbian-stretch.img
[sudo] password for wind:

Disk 2017-11-29-raspbian-stretch.img: 4919 MB, 4919918592 bytes
255 heads, 63 sectors/track, 598 cylinders, total 9609216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x49783f5b

                          Device Boot      Start         End      Blocks   Id  System
2017-11-29-raspbian-stretch.img1            8192       93236       42522+   c  W95 FAT32 (LBA)
2017-11-29-raspbian-stretch.img2           94208     9609215     4757504   83  Linux

### offset = 94208 * 512 = 48234496
$ sudo mount -o loop,offset=48234496 2017-11-29-raspbian-stretch.img /mnt
$ cd /mnt
ROOTFS=/mnt
TOOLCHAIN=/path/to/gcc-linaro-4.9-2015.02-3-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-

配置

$ tar -xJvf qt-everywhere-src-5.10.0.tar.xz
$ cd qt-everywhere-src-5.10.0
$ ./configure -opengl es2 -device linux-rasp-pi3-g++ -device-option CROSS_COMPILE=/home/wind/opt/raspi/tools/arm-bcm2708/gcc-linaro-4.9-2015.02-3-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- -sysroot /mnt -opensource -confirm-license -optimized-qmake -reduce-exports -release -make libs -prefix /usr/local/qt5
### add -make tools -make examples options if need

此时出下面的错误

ERROR: Cannot compile a minimal program. The toolchain or QMakeSpec is broken.
ERROR: The OpenGL functionality tests failed! You might need to modify the include and library search paths
by editing QMAKE_INCDIR_OPENGL[_ES2], QMAKE_LIBDIR_OPENGL[_ES2] and QMAKE_LIBS_OPENGL[_ES2] in the mkspec for your platform.

修改文件linux-rasp-pi3-g++/qmake.conf如下:

VC_LIBRARY_PATH         = $$[QT_SYSROOT]/opt/vc/lib
VC_INCLUDE_PATH         = $$[QT_SYSROOT]/opt/vc/include

QMAKE_LIBDIR_OPENGL_ES2 = $${VC_LIBRARY_PATH}
QMAKE_LIBDIR_EGL        = $$QMAKE_LIBDIR_OPENGL_ES2
QMAKE_LIBDIR_OPENVG     = $$QMAKE_LIBDIR_OPENGL_ES2

QMAKE_INCDIR_EGL        = \
                        $${VC_INCLUDE_PATH} \
                        $${VC_INCLUDE_PATH}/interface/vcos/pthreads \
                        $${VC_INCLUDE_PATH}/interface/vmcs_host/linux
QMAKE_INCDIR_OPENGL_ES2 = $${QMAKE_INCDIR_EGL}
QMAKE_INCDIR_OPENVG     = $${QMAKE_INCDIR_EGL}

QMAKE_LIBS_OPENGL_ES2   = -lGLESv2
QMAKE_LIBS_EGL          = -lEGL -lGLESv2
QMAKE_LIBS_OPENVG       = -lEGL -lOpenVG -lGLESv2
  • Configure script
  • qmake.config

所有错误修复之后,重新配置,创建qmake文件成功,输出成功信息

+ cd qtbase
### ..............
Creating qmake...
........................................
.Done.

This is the Qt Open Source Edition.

You have already accepted the terms of the Open Source license.

Running configuration tests...
Done running configuration tests.

Configure summary:

Building on: linux-g++ (x86_64, CPU features: mmx sse sse2)
Building for: devices/linux-rasp-pi3-g++ (arm, CPU features: neon)
Configuration: cross_compile compile_examples enable_new_dtags largefile neon precompile_header shared rpath release c++11 c++14 concurrent dbus reduce_exports release_tools stl
Build options:
  Mode ................................... release; optimized tools
  Optimize release build for size ........ no
  Building shared libraries .............. yes
  Using C++ standard ..................... C++14
  Using ccache ........................... no
  Using gold linker ...................... no
  Using new DTAGS ........................ yes
  Using precompiled headers .............. yes
  Using LTCG ............................. no
  Target compiler supports:
    NEON ................................. yes
  Build parts ............................ libs

### ..................

Note: Also available for Linux: linux-clang linux-icc

Note: -optimized-tools is not useful in -release mode.

Note: No wayland-egl support detected. Cross-toolkit compatibility disabled.

Qt is now configured for building. Just run 'make'.
Once everything is built, you must run 'make install'.
Qt will be installed into '/mnt/usr/local/qt5'.

Prior to reconfiguration, make sure you remove any leftovers from
the previous build.

编译

$ make
### or
$ make -j4

编译错误修复

error: cannot open /mnt/usr/lib/arm-linux-gnueabihf/libz.so: No such file or directory

### and libm.so, librt.so, libdl.so

undefined reference to `__dlsym'

make *** [sub-src-make_first] Error 2

arm-linux-gnueabihf/bin/ld: cannot find -lm
### and -lc

错误原因:

根文件系统中有些库的软连接是绝对路径,但我们的镜像是挂载到主机的,所以找不到链接文件导致错误,修改方法是使用相对路径重新创建软连接

$ cd /mnt/usr/lib/arm-linux-gnueabihf/
$ sudo rm libdl.so
$ sudo ln -s ../../../lib/arm-linux-gnueabihf/libdl.so.2 libdl.so
$ sudo rm libz.so
$ sudo ln -s ../../../lib/arm-linux-gnueabihf/libz.so.1 libz.so
$ sudo rm libutil.so
$ sudo ln -s ../../../lib/arm-linux-gnueabihf/libutil.so.1 libutil.so
$ sudo rm librt.so
$ sudo ln -s ../../../lib/arm-linux-gnueabihf/librt.so.1 librt.so
$ sudo rm libm.so
$ sudo ln -s ../../../lib/arm-linux-gnueabihf/libm.so.6 libm.so

###  /lib/arm-linux-gnueabihf/ 也可能需要相同的软连接

$ cd /mnt/lib/arm-linux-gnueabihf/
$ sudo ln -s libz.so.1 libz.so
$ sudo ln -s libdl.so.2 libdl.so
$ sudo ln -s librt.so.1 librt.so
$ sudo ln -s libm.so.6 libm.so

### 一些重命名的文件和软连接 EGL, GLESv2, OpenVG

$ cd /mnt/opt/vc/lib
$ sudo ln -s libbrcmEGL.so libEGL.so
$ sudo ln -s libbrcmGLESv2.so libGLESv2.so
$ sudo ln -s libbrcmOpenVG.so libOpenVG.so
$ sudo ln -s libbrcmWFC.so libWFC.so

修复之后编译成功,可以安装

$ sudo make install

### all files will be install to '/mnt/usr/local/qt5'

最后,卸载镜像, sudo umount /mnt

将新的镜像写入SD卡,并重新启动树莓派

使用 dd 命令写入镜像

$ sudo umount /dev/sdd1
$ sudo umount /dev/sdd2
$ sudo dd bs=4M if=2017-11-29-raspbian-stretch.img of=/dev/sdd

重新启动

References

  • RaspberryPi
  • Raspberry Pi Beginners Guide
  • Qt for Embedded Linux

你可能感兴趣的:(Raspi,raspberry,pi,Raspi,qt5)