Ubuntu16.04 Qt5.14.2交叉编译树莓派4B开发环境搭建-保姆级教程(带远程调试、亲测有效)

Ubuntu16.04 Qt5.14.2交叉编译树莓派4B,带一键部署和远程调试

  • 前言
    • 开发环境介绍
    • 相关软件工具
  • 一、(宿主机)树莓派4B上操作
    • (1) 更新软件源
    • (2)升级系统固件
    • (3) 安装相关依赖软件
    • (4) 新建交叉编译QT库存放文件
  • 二、(主机)Ubuntu 上的操作
    • (1) 更新软件
    • (2) 下载相关软件
    • (3) 准备交叉编译工具
    • (4) 下载Qt源码
    • (5) 拷贝树莓派文件到sysroot
    • (6) 移除mesa的opengl库文件,使用树莓派自带GPU加速库
    • (7) 使用sysroot-relativelinks.py脚本修改sysroot里面的软链接
    • (8) 配置并编译Qt源码
  • 三、Qtcreator配置远程调试
    • (1) 添加设备
    • (2) 配置qmake
    • (3) 配置交叉编译器
    • (4) 配置调试器
    • (5) 添加树莓派4B编译套件Kit
  • 五、测试

前言

最近在树莓派4B开发一个Qt项目,记录一下交叉编译过程中需要的一些问题,希望能帮到有需要的朋友。

开发环境介绍

主机
台式机-R5 2600X 16G内存
Ubuntu 16.04

宿主机
树莓派4B、4G内存、32G SD卡
Raspbian buster 2019-07-13 【32位】

相关软件工具

树莓派系统镜像(官网)
树莓派固件升级包)
交叉编译工具链
Qt源码
软链接处理脚本

本文用到的软件工具版本
(1)树莓派系统镜像:Raspbian buster 2019-07-13 【32位】
(2)树莓派固件升级包:
(3)交叉编译工具链

GCC:gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz
sysroot:sysroot-glibc-linaro-2.25-2019.12-arm-linux-gnueabihf.tar.xz
runtime:runtime-gcc-linaro-7.5.0-2019.12-arm-linux-gnueabihf.tar.xz

(4)Qt源码:qt-everywhere-src-5.14.2.tar.xz
(5) 软链接处理脚本:https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py

注意事项
(1) 如果下载慢可以使用迅雷下载
(2) 工具链可以是比树莓派系统镜像新,但不能低于系统镜像版本
(3)Qt源码要下载支持树莓派4B设备的,源码版本选 single>*.tar.xz的;
*.zip的是windows的,在编译源码时经常报错(亲测,贼坑)。

Qt源码下载:
Ubuntu16.04 Qt5.14.2交叉编译树莓派4B开发环境搭建-保姆级教程(带远程调试、亲测有效)_第1张图片

本文软件工具打包
百度云:

相关软件工具准备好后就开始正式操作了。

一、(宿主机)树莓派4B上操作

建议:

将树莓派和主机电脑连接到同一网络,开启树莓派ssh服务,操作起来更便捷高效!

主机IP: 192.168.3.14
宿主机IP: 192.168.3.10

ssh登录
Ubuntu16.04 Qt5.14.2交叉编译树莓派4B开发环境搭建-保姆级教程(带远程调试、亲测有效)_第2张图片

(1) 更新软件源

删除一些树莓派系统自带的软件,节省空间

1.先让系统升级到最新
	sudo apt-get update

2.下载的套件依旧在,移除掉因依赖关系而自动安装的套件
	sudo apt-get cleandf -h
	sudo apt-get autoremove --purge

3.移除IBM的Node-RED、Mathematica、Scratch、Sonic Pi、Minecraft Pi
	sudo apt-get remove --purge --auto-remove nodered wolfram-engine scratch sonic-pi minecraft-pi

4.再移除两套Java IDE:BlueJ與Greenfoot,一套轻量型IDE:Geany
	sudo apt-get remove --purge --auto-remove bluej greenfoot geany

5.移除掉Sense HAT Emulator
	sudo apt-get remove --purge --auto-remove python-sense-emu python3-sense-emu python-sense-emu-doc sense-emu-tools

6.移除掉浏览器(保留谷歌浏览器,因为项目中用到了谷歌浏览器)
	sudo apt-get remove --purge --auto-remove claws-mail rpi-chromium-mods epiphany-browser dillo

7.移除Libre Office(后边的*意思是全部移除)
	sudo apt-get remove --purge --auto-remove libreoffice*

更新国内软件源

	deb https://mirrors.bfsu.edu.cn/raspbian/raspbian/ ==buster== main contrib non-free rpi
	deb-src https://mirrors.bfsu.edu.cn/raspbian/raspbian/ ==buster==  main contrib non-free rpi

注意事项
软件源 buster 关键字要与树莓派实际系统版本对应

	sudo nano /etc/apt/sources.list

复制源码连接到 /etc/apt/sources.list 文件中,注释掉之前的软件源
Ubuntu16.04 Qt5.14.2交叉编译树莓派4B开发环境搭建-保姆级教程(带远程调试、亲测有效)_第3张图片
Ctrl+O保存
Ctrl+X退出

退出后更新软件

	sudo apt-get update

(2)升级系统固件

将下载好的固件升级包通过FTP传输到树莓派4B上
Ubuntu16.04 Qt5.14.2交叉编译树莓派4B开发环境搭建-保姆级教程(带远程调试、亲测有效)_第4张图片
Ubuntu16.04 Qt5.14.2交叉编译树莓派4B开发环境搭建-保姆级教程(带远程调试、亲测有效)_第5张图片
Ubuntu16.04 Qt5.14.2交叉编译树莓派4B开发环境搭建-保姆级教程(带远程调试、亲测有效)_第6张图片
具体固件升级操作参考一下链接

树莓派固件升级

(3) 安装相关依赖软件

sudo apt-get install build-essential qt5-qmake libqt5webengine-data
sudo apt-get install libboost1.58-all-dev libudev-dev libinput-dev libts-dev libmtdev-dev libjpeg-dev libfontconfig1-dev libdbus*
sudo apt-get install libssl-dev libdbus-1-dev libglib2.0-dev libxkbcommon-dev libegl1-mesa-dev libgbm-dev libgles2-mesa-dev mesa-common-dev
sudo apt-get install libasound2-dev libpulse-dev gstreamer1.0-omx libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-alsa
sudo apt-get install libvpx-dev libsrtp0-dev libsnappy-dev libnss3-dev
sudo apt-get install "^libxcb.*" 
sudo apt-get install libfreetype6-dev libicu-dev libsqlite3-dev libxslt1-dev libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install libgstreamer0.10-dev gstreamer-tools libraspberrypi-dev libx11-dev libglib2.0-dev
sudo apt-get install freetds-dev libsqlite0-dev libpq-dev libiodbc2-dev firebird-dev libjpeg9-dev libgst-dev libxext-dev libxcb1 libxcb1-dev libx11-xcb1
sudo apt-get install libxcb-sync-dev libxcb-render-util0 libxcb-render-util0-dev libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev
sudo apt-get install libxcb-glx0-dev libxi-dev libdrm-dev libssl-dev libxcb-xinerama0 libxcb-xinerama0-dev
sudo apt-get install libatspi-dev libssl-dev libxcursor-dev libxcomposite-dev libxdamage-dev libfontconfig1-dev
sudo apt-get install libxss-dev libxtst-dev libpci-dev libcap-dev libsrtp0-dev libxrandr-dev libnss3-dev libdirectfb-dev libaudio-dev

(4) 新建交叉编译QT库存放文件

	sudo mkdir /usr/local/qt5pi
	sudo chown pi:pi /usr/local/qt5pi

至此树莓派上的操作已完成,接下来就是Ubuntu上的配置了


二、(主机)Ubuntu 上的操作

(1) 更新软件

	sudo apt-get update
	sudo apt-get upgrade

(2) 下载相关软件

	sudo apt-get install gcc git bison python gperf pkg-config libclang-dev

(3) 准备交叉编译工具

新建树莓派工作文件夹

	mkdir Raspberry;cd Raspberry

新建交叉编译工具文件夹

	mkdir cross-compile-tool

将下载好的交叉编译工具链解压合并到 cross-compile-tool 文件夹中

GCC:gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz
sysroot:sysroot-glibc-linaro-2.25-2019.12-arm-linux-gnueabihf.tar.xz
runtime:runtime-gcc-linaro-7.5.0-2019.12-arm-linux-gnueabihf.tar.xz

Ubuntu16.04 Qt5.14.2交叉编译树莓派4B开发环境搭建-保姆级教程(带远程调试、亲测有效)_第7张图片
将交叉编译器添加到环境变量中

	export PATH=$PATH:/home/yoyo/Raspberry/cross-compile-tool/bin

测试:
Ubuntu16.04 Qt5.14.2交叉编译树莓派4B开发环境搭建-保姆级教程(带远程调试、亲测有效)_第8张图片

(4) 下载Qt源码

Qt源码目录: https://download.qt.io/archive/qt/5.14/5.14.2/single/
Qt5.14.2源码链接: https://download.qt.io/archive/qt/5.14/5.14.2/single/qt-everywhere-src-5.14.2.tar.xz

注意
(1)下载549M内存小的源码压缩包
(3)空间较大的那个版本为Windows源码版本,在编译过程中容易出错 (贼坑),下载使用 dos2unix工具转换文件格式可解决,但编译仍会出错
(2)下载慢的,可以使用迅雷下载

将下载好的源码解压到 /home/yoyo/Raspberry 文件中
在这里插入图片描述

(5) 拷贝树莓派文件到sysroot

在树莓派工作文件夹下新建sysroot文件夹
mkdir sysroot

指令格式: rsync -avz 树莓派用户名@树莓派IP:源文件路径 目标文件路径

rsync -avz pi@192.168.3.10:/lib sysroot
rsync -avz pi@192.168.3.10:/usr/include sysroot/usr
rsync -avz pi@192.168.3.10:/usr/lib sysroot/usr
rsync -avz pi@192.168.3.10:/opt/vc sysroot/opt

在这里插入图片描述

文件下载完成
Ubuntu16.04 Qt5.14.2交叉编译树莓派4B开发环境搭建-保姆级教程(带远程调试、亲测有效)_第9张图片

(6) 移除mesa的opengl库文件,使用树莓派自带GPU加速库

mv sysroot/usr/lib/arm-linux-gnueabihf/libEGL.so.1.1.0 sysroot/usr/lib/arm-linux-gnueabihf/libEGL.so.1.1.0_backup
mv sysroot/usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.1.0 sysroot/usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.1.0_backup
ln -s sysroot/opt/vc/lib/libEGL.so sysroot/usr/lib/arm-linux-gnueabihf/libEGL.so.1.1.0
ln -s sysroot/opt/vc/lib/libGLESv2.so sysroot/usr/lib/arm-linux-gnueabihf/libGLESv2.so.2.1.0
ln -s sysroot/opt/vc/lib/libEGL.so sysroot/opt/vc/lib/libEGL.so.1
ln -s sysroot/opt/vc/lib/libGLESv2.so sysroot/opt/vc/lib/libGLESv2.so.2

(7) 使用sysroot-relativelinks.py脚本修改sysroot里面的软链接

<1>(有脚本文件的)将脚本复制到~/Raspberry目录下后,运行脚本

	./sysroot-relativelinks.py sysroot

<2>(没有脚本文件的)在~/Raspberry目录下新建sysroot-relativelinks.py文件,将以下内容复制到文件中

#!/usr/bin/env python
import sys
import os

# Take a sysroot directory and turn all the abolute symlinks and turn them into
# relative ones such that the sysroot is usable within another system.

if len(sys.argv) != 2:
    print("Usage is " + sys.argv[0] + "")
    sys.exit(1)

topdir = sys.argv[1]
topdir = os.path.abspath(topdir)

def handlelink(filep, subdir):
    link = os.readlink(filep)
    if link[0] != "/":
        return
    if link.startswith(topdir):
        return
    #print("Replacing %s with %s for %s" % (link, topdir+link, filep))
    print("Replacing %s with %s for %s" % (link, os.path.relpath(topdir+link, subdir), filep))
    os.unlink(filep)
    os.symlink(os.path.relpath(topdir+link, subdir), filep)

for subdir, dirs, files in os.walk(topdir):
    for f in files:
        filep = os.path.join(subdir, f)
        if os.path.islink(filep):
            #print("Considering %s" % filep)
            handlelink(filep, subdir)
chmod +x sysroot-relativelinks.py
./sysroot-relativelinks.py sysroot

再次更新文件

rsync -avz pi@192.168.3.10:/lib sysroot
rsync -avz pi@192.168.3.10:/usr/include sysroot/usr
rsync -avz pi@192.168.3.10:/usr/lib sysroot/usr
rsync -avz pi@192.168.3.10:/opt/vc sysroot/opt

修改软连接

./sysroot-relativelinks.py sysroot

到此编译环境准备完成

(8) 配置并编译Qt源码

<1> 新建源码编译文件夹

	mkdir qt5build;cd qt5build

<2>配置Qt源码让其支持树莓派4B设备

../qt-everywhere-src-5.14.2/configure \
-release \
-opengl es2 \
-device linux-rasp-pi4-v3d-g++ \
-device-option CROSS_COMPILE=/home/yoyo/Raspberry/cross-compile-tool/bin/arm-linux-gnueabihf- \
-sysroot /home/yoyo/Raspberry/sysroot \
-prefix /usr/local/qt5pi \
-extprefix ~/Raspberry/qt5pi \
-hostprefix ~/Raspberry/qt5pi-host \
-opensource -confirm-license \
-skip qtscript \
-skip qtwayland \
-skip qtdatavis3d \
-nomake examples \
-make libs -pkg-config \
-no-use-gold-linker -v

各参数具体说明请参考./config_help.txt:

-device linux-rasp-pi4-v3d-g++ :使用qtbase/mkspecs/device/linux-rasp-pi4-v3d-g++下的配置
-device-option CROSS_COMPILE=~/Raspberry/cross-compile-tool/bin/arm-linux-gnueabihf- : 交叉编译工具链的前缀,注意最后那个“-”号是不能少的
-prefix /usr/local/qt5pi: Qt最终安装到树莓派中的位置
-extprefix ~/Raspberry/qt5pi: PC上交叉编译好的Qt的位置
-hostprefix ~/Raspberry/qt5pi-host: 编译出来给PC用的交叉编译工具存放的位置

配置结果

Configure summary:

Building on: linux-g++ (x86_64, CPU features: mmx sse sse2)
Building for: devices/linux-rasp-pi4-v3d-g++ (arm, CPU features: neon)
Target compiler: gcc 7.5.0
Configuration: cross_compile compile_examples enable_new_dtags largefile neon precompile_header shared shared rpath release c++11 c++14 c++1z concurrent dbus reduce_exports stl
Build options:
  Mode ................................... release
  Optimize release build for size ........ no
  Building shared libraries .............. yes
  Using C standard ....................... C11
  Using C++ standard ..................... C++17
  Using ccache ........................... no
  Using new DTAGS ........................ yes
  Relocatable ............................ yes
  Using precompiled headers .............. yes
  Using LTCG ............................. no
  Target compiler supports:
    NEON ................................. yes
  Build parts ............................ libs
Qt modules and options:
  Qt Concurrent .......................... yes
  Qt D-Bus ............................... yes
  Qt D-Bus directly linked to libdbus .... yes
  Qt Gui ................................. yes
  Qt Network ............................. yes
  Qt Sql ................................. yes
  Qt Testlib ............................. yes
  Qt Widgets ............................. yes
  Qt Xml ................................. yes
Support enabled for:
  Using pkg-config ....................... yes
  udev ................................... yes
  Using system zlib ...................... yes
  Zstandard support ...................... no
Qt Core:
  DoubleConversion ....................... yes
    Using system DoubleConversion ........ no
  GLib ................................... yes
  iconv .................................. no
  ICU .................................... yes
  Built-in copy of the MIME database ..... yes
  Tracing backend ........................ <none>
  Logging backends:
    journald ............................. no
    syslog ............................... no
    slog2 ................................ no
  PCRE2 .................................. yes
    Using system PCRE2 ................... no
Qt Network:
  getifaddrs() ........................... yes
  IPv6 ifname ............................ yes
  libproxy ............................... no
  Linux AF_NETLINK ....................... yes
  OpenSSL ................................ yes
    Qt directly linked to OpenSSL ........ no
  OpenSSL 1.1 ............................ yes
  DTLS ................................... yes
  OCSP-stapling .......................... yes
  SCTP ................................... no
  Use system proxies ..................... yes
  GSSAPI ................................. no
Qt Gui:
  Accessibility .......................... yes
  FreeType ............................... yes
    Using system FreeType ................ yes
  HarfBuzz ............................... yes
    Using system HarfBuzz ................ yes
  Fontconfig ............................. yes
  Image formats:
    GIF .................................. yes
    ICO .................................. yes
    JPEG ................................. yes
      Using system libjpeg ............... yes
    PNG .................................. yes
      Using system libpng ................ yes
  Text formats:
    HtmlParser ........................... yes
    CssParser ............................ yes
    OdfWriter ............................ yes
    MarkdownReader ....................... yes
      Using system libmd4c ............... no
    MarkdownWriter ....................... yes
  EGL .................................... yes
  OpenVG ................................. no
  OpenGL:
    Desktop OpenGL ....................... no
    OpenGL ES 2.0 ........................ yes
    OpenGL ES 3.0 ........................ yes
    OpenGL ES 3.1 ........................ yes
    OpenGL ES 3.2 ........................ yes
  Vulkan ................................. yes
  Session Management ..................... yes
Features used by QPA backends:
  evdev .................................. yes
  libinput ............................... yes
  INTEGRITY HID .......................... no
  mtdev .................................. yes
  tslib .................................. yes
  xkbcommon .............................. yes
  X11 specific:
    XLib ................................. yes
    XCB Xlib ............................. no
    EGL on X11 ........................... yes
QPA backends:
  DirectFB ............................... no
  EGLFS .................................. yes
  EGLFS details:
    EGLFS OpenWFD ........................ no
    EGLFS i.Mx6 .......................... no
    EGLFS i.Mx6 Wayland .................. no
    EGLFS RCAR ........................... no
    EGLFS EGLDevice ...................... yes
    EGLFS GBM ............................ yes
    EGLFS VSP2 ........................... no
    EGLFS Mali ........................... no
    EGLFS Raspberry Pi ................... no
    EGLFS X11 ............................ no
  LinuxFB ................................ yes
  VNC .................................... yes
  XCB:
    Using system-provided XCB libraries .. yes
    XCB XKB .............................. no
    XCB XInput ........................... yes
    Native painting (experimental) ....... no
    GL integrations:
      GLX Plugin ......................... no
      EGL-X11 Plugin ..................... yes
Qt Sql:
  SQL item models ........................ yes
Qt Widgets:
  GTK+ ................................... no
  Styles ................................. Fusion Windows
Qt PrintSupport:
  CUPS ................................... no
Qt Sql Drivers:
  DB2 (IBM) .............................. no
  InterBase .............................. no
  MySql .................................. no
  OCI (Oracle) ........................... no
  ODBC ................................... no
  PostgreSQL ............................. yes
  SQLite2 ................................ yes
  SQLite ................................. yes
    Using system provided SQLite ......... no
  TDS (Sybase) ........................... yes
Qt Testlib:
  Tester for item models ................. yes
Serial Port:
  ntddmodm ............................... no
Qt SerialBus:
  Socket CAN ............................. yes
  Socket CAN FD .......................... yes
  SerialPort Support ..................... yes
Further Image Formats:
  JasPer ................................. no
  MNG .................................... no
  TIFF ................................... yes
    Using system libtiff ................. no
  WEBP ................................... yes
    Using system libwebp ................. no
Qt QML:
  QML network support .................... yes
  QML debugging and profiling support .... yes
  QML just-in-time compiler .............. yes
  QML sequence object .................... yes
  QML XML http request ................... yes
  QML Locale ............................. yes
Qt QML Models:
  QML list model ......................... yes
  QML delegate model ..................... yes
Qt Quick:
  Direct3D 12 ............................ no
  AnimatedImage item ..................... yes
  Canvas item ............................ yes
  Support for Qt Quick Designer .......... yes
  Flipable item .......................... yes
  GridView item .......................... yes
  ListView item .......................... yes
  TableView item ......................... yes
  Path support ........................... yes
  PathView item .......................... yes
  Positioner items ....................... yes
  Repeater item .......................... yes
  ShaderEffect item ...................... yes
  Sprite item ............................ yes
QtQuick3D:
  Assimp ................................. yes
  System Assimp .......................... no
Qt Scxml:
  ECMAScript data model for QtScxml ...... yes
Qt Gamepad:
  SDL2 ................................... no
Qt 3D:
  Assimp ................................. yes
  System Assimp .......................... no
  Output Qt3D Job traces ................. no
  Output Qt3D GL traces .................. no
  Use SSE2 instructions .................. no
  Use AVX2 instructions .................. no
  Aspects:
    Render aspect ........................ yes
    Input aspect ......................... yes
    Logic aspect ......................... yes
    Animation aspect ..................... yes
    Extras aspect ........................ yes
Qt 3D Renderers:
  OpenGL Renderer ........................ yes
Qt 3D GeometryLoaders:
  Autodesk FBX ........................... no
Qt Bluetooth:
  BlueZ .................................. no
  BlueZ Low Energy ....................... no
  Linux Crypto API ....................... no
  Native Win32 Bluetooth ................. no
  WinRT Bluetooth API (desktop & UWP) .... no
  WinRT advanced bluetooth low energy API (desktop & UWP) . no
Qt Sensors:
  sensorfw ............................... no
Qt Quick Controls 2:
  Styles ................................. Default Fusion Imagine Material Universal
Qt Quick Templates 2:
  Hover support .......................... yes
  Multi-touch support .................... yes
Qt Positioning:
  Gypsy GPS Daemon ....................... no
  WinRT Geolocation API .................. no
Qt Location:
  Qt.labs.location experimental QML plugin . yes
  Geoservice plugins:
    OpenStreetMap ........................ yes
    HERE ................................. yes
    Esri ................................. yes
    Mapbox ............................... yes
    MapboxGL ............................. yes
    Itemsoverlay ......................... yes
QtXmlPatterns:
  XML schema support ..................... yes
Qt Multimedia:
  ALSA ................................... yes
  GStreamer 1.0 .......................... yes
  GStreamer 0.10 ......................... no
  Video for Linux ........................ yes
  OpenAL ................................. no
  PulseAudio ............................. yes
  Resource Policy (libresourceqt5) ....... no
  Windows Audio Services ................. no
  DirectShow ............................. no
  Windows Media Foundation ............... no
Qt TextToSpeech:
  Flite .................................. no
  Flite with ALSA ........................ no
  Speech Dispatcher ...................... no
Qt Tools:
  QDoc ................................... no
Qt WebEngine Build Tools:
  Use System Ninja ....................... no
  Use System Gn .......................... no
  Jumbo Build Merge Limit ................ 8
  Developer build ........................ no
  QtWebEngine required system libraries:
    fontconfig ........................... yes
    dbus ................................. yes
    nss .................................. yes
    khr .................................. yes
    glibc ................................ yes
  QtWebEngine required system libraries for qpa-xcb:
    x11 .................................. no
    libdrm ............................... yes
    xcomposite ........................... no
    xcursor .............................. no
    xi ................................... no
    xtst ................................. no
  Optional system libraries used:
    re2 .................................. no
    icu .................................. no
    libwebp, libwebpmux and libwebpdemux . no
    opus ................................. no
    ffmpeg ............................... no
    libvpx ............................... no
    snappy ............................... yes
    glib ................................. yes
    zlib ................................. yes
    minizip .............................. no
    libevent ............................. no
    jsoncpp .............................. no
    protobuf ............................. no
    libxml2 and libxslt .................. yes
    lcms2 ................................ no
    png .................................. yes
    JPEG ................................. yes
    harfbuzz ............................. yes
    freetype ............................. yes

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

Note: PKG_CONFIG_LIBDIR automatically set to /home/yoyo/Raspberry/sysroot/usr/lib/pkgconfig:/home/yoyo/Raspberry/sysroot/usr/share/pkgconfig:/home/yoyo/Raspberry/sysroot/usr/lib/arm-linux-gnueabihf/pkgconfig

Note: PKG_CONFIG_SYSROOT_DIR automatically set to /home/yoyo/Raspberry/sysroot

Note: The following modules are not being compiled in this configuration:
    webenginecore
    webengine
    webenginewidgets

WARNING: QDoc will not be compiled, probably because libclang could not be located. This means that you cannot build the Qt documentation.

Either ensure that llvm-config is in your PATH environment variable, or set LLVM_INSTALL_DIR to the location of your llvm installation.
On Linux systems, you may be able to install libclang by installing the libclang-dev or libclang-devel package, depending on your distribution.
On macOS, you can use Homebrew's llvm package.
On Windows, you must set LLVM_INSTALL_DIR to the installation path.

WARNING: Tool flex is required to build QtWebEngine.

WARNING: QtWebEngine will not be built.

WARNING: QtPdf will not be built.

Qt is now configured for building. Just run 'make'.
Once everything is built, you must run 'make install'.
Qt will be installed into '/home/yoyo/Raspberry/qt5pi'.

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

注意事项

1、EGL on X11 、EGLFS、EGLFS EGLDevice、EGLFS GBM 4个都必须是 yes,配置就算是完成了。(不然就出大问题,不能在PC机上显示软件)
2、EGLFS Raspberry Pi 后面是no是对的,因为它代表的是树莓派3以前的旧驱动(brcm),树莓派4不用的。
3、如果出了问题,检查config.log,挨个排查问题吧。排查完后删除config.log和config.cache,重新执行前面的./configure

如果配成成功了,接下来就是编译源码阶段了

make -j12 && sudo make install

-j:指定要同时运行的作业数,一般以CPU核心数2倍为宜。

编译过程较长,请耐心等待
Ubuntu16.04 Qt5.14.2交叉编译树莓派4B开发环境搭建-保姆级教程(带远程调试、亲测有效)_第10张图片

然而这只是编译了qtbase,很多其他的组件都是没有的。如果你想要其他的module,可以到其他文件夹里编译。

将编译好的qt5pi发送到树莓派文件系统中
rsync -avz qt5pi [email protected]:/usr/local

至此交叉编译环境就完成了

三、Qtcreator配置远程调试

没有安装QtCreator的就自行下载安装吧
Qt下载
本文用的是QT5.14.2版本

(1) 添加设备

Qt Creator->工具–>选项–>设备–>添加–>通用Linux设备

<1> 添加设备
Ubuntu16.04 Qt5.14.2交叉编译树莓派4B开发环境搭建-保姆级教程(带远程调试、亲测有效)_第11张图片
Ubuntu16.04 Qt5.14.2交叉编译树莓派4B开发环境搭建-保姆级教程(带远程调试、亲测有效)_第12张图片
生成秘钥
完成设备添加,点击右边Test按钮测试能否成功连接树莓派

(2) 配置qmake

Ubuntu16.04 Qt5.14.2交叉编译树莓派4B开发环境搭建-保姆级教程(带远程调试、亲测有效)_第13张图片

此qmake是交叉编译出的,在配置源码时的-hostprefix 后的路径中

	/home/yoyo/Raspberry/qt5pi-host/bin

(3) 配置交叉编译器

Tools–>Options–>Kits–>Compilers 添加(Add):GCC–>C 和 GCC–>C++
Ubuntu16.04 Qt5.14.2交叉编译树莓派4B开发环境搭建-保姆级教程(带远程调试、亲测有效)_第14张图片

C的配置
Name:arm-linux-gnueabihf-gcc
Path:/home/yoyo/Raspberry/cross-compile-tool/bin/arm-linux-gnueabihf-gcc
C++的配置
Name:arm-linux-gnueabihf-g++
Path:/home/yoyo/Raspberry/cross-compile-tool/bin/arm-linux-gnueabihf-g++

(4) 配置调试器

Tools–>Options–>Kits–>Debuggers 添加(Add)
Ubuntu16.04 Qt5.14.2交叉编译树莓派4B开发环境搭建-保姆级教程(带远程调试、亲测有效)_第15张图片

Name:arm-linux-gnueabihf-gdb
Path:/home/yoyo/Raspberry/cross-compile-tool/bin/arm-linux-gnueabihf-gdb

(5) 添加树莓派4B编译套件Kit

Ubuntu16.04 Qt5.14.2交叉编译树莓派4B开发环境搭建-保姆级教程(带远程调试、亲测有效)_第16张图片

Device Type: Geneic Linux Device
Device : Raspberry4B
sysroot: /home/yoyo/Raspberry/sysroot
Compiler: arm-linux-gnueabihf-gcc、arm-linux-gnueabihf-g++
Debugger: arm-linux-gnueabihf-gdb
Qt Version: Qt5.14.2(qt5pi-host)

保存退出,重启Qt Creator。

五、测试

你可能感兴趣的:(树莓派4B,交叉编译,远程部署调试,qt,linux)