交叉编译树莓派QT5.10

交叉编译树莓派QT5.10

环境准备

挂载镜像

挂载镜像更稳健系统到 /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

所有错误修复之后,重新配置,创建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

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Windows 上交叉编译树莓派上的 Qt 程序,需要先安装交叉编译工具链和 Qt for Raspberry Pi。 以下是具体步骤: 1. 安装交叉编译工具链 下载 Raspberry Pi交叉编译工具链(例如 arm-linux-gnueabihf)并解压到本地。可以从树莓派官网下载或使用 apt-get 命令安装。 2. 安装 Qt for Raspberry Pi 下载 Qt for Raspberry Pi交叉编译版本并安装到本地。 3. 配置 Qt Creator 打开 Qt Creator,选择“工具”->“选项”->“设备”->“添加”,填写以下信息: - 设备类型:通用 Linux 设备 - 设备名称:任意 - IP 地址:填写树莓派的 IP 地址 - 端口号:默认 22 - 用户名:填写树莓派的用户名 - 密码:填写树莓派的密码 - SSH 密钥文件:如果有,填写私钥文件的路径 保存并应用配置。 4. 创建 Qt 项目 创建一个新的 Qt 项目,在“项目设置”中选择“通用 Linux 设备”作为目标设备。 5. 配置编译选项 在项目设置中,选择“构建和运行”->“构建步骤”->“qmake”,修改“qmake 引数”为: ``` -spec linux-g++-32 -P <Qt for Raspberry Pi 安装路径>/mkspecs/rasp-pi-g++ ``` 然后选择“构建和运行”->“构建步骤”->“Make”,修改“Make 引数”为: ``` -j4 ARCH=arm CROSS_COMPILE=<交叉编译工具链路径>/bin/arm-linux-gnueabihf- ``` 6. 编译和部署 通过 Qt Creator 编译项目,并通过 SSH 将生成的文件复制到树莓派上。在树莓派上运行程序即可。 以上是在 Windows 上交叉编译树莓派上的 Qt 程序的步骤,希望能对你有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值