Qt5.9.6 ARM平台 移植 交叉编译

前言

目前大多数开发板自带Qt环境,但是版本较为落后,多数都为Qt4.8的版本,都9102年了,已经无法满足现在的开发需求,所以现在记录一下Qt5.9.6的交叉编译。一方面是为了自己大学的学习的积累和总结,另一方面也是为了刚接触嵌入式开发的小白不要像我一样在移植时到处碰壁。
Here we go !

编译前准备工作

  1. 平台及资源
    主机环境:ubuntu 14.04
    开发板 :米尔科技 ARM 335X 系列
    Qt:qt-everywhere-opensource-src-5.9.6.tar.xz 建议下载源码压缩包,run后缀的安装包文件比较大,而且不方便交叉编译。
    编译器:arm-linux-gnueabihf 交叉编译器最好选择开发板厂商提供的交叉编译工具链 (Qt5.9 所需的编译器版本必须是4.8版本以上)

  2. 交叉编译器配置环境变量
    在~/.profile中添加环境变量指定到交叉编译器的bin目录下,例如:
    export PATH=$PATH:/home/linux/work/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin
    并执行 source ~/.profile 使配置生效
    使用 arm-linux-gnueabihf-gcc -v 命令查看当前版本号,同时检查环境变量配置是否生效。
    在这里插入图片描述

    OK !如果成功打印出了版本号,说明第一步已经完成。接下来就可以开始移植一系列的软件了,此处和Qt一同编译的还有触摸屏所需tslib和数据库SQLite3,这两个已经完成交叉编译了,详情可以查看我的前两篇博客。
    tslib 交叉编译
    SQLite3 交叉编译

开始Qt的编译

  1. 修改qmake.conf文件
    Qt5支持相当多嵌入式平台的移植,针对每一种平台都有相应的配置文件夹,只需修改你想要移植的目标平台对应的文件夹,再在之后的./configure脚本指定你想要编译的文件夹即可完成对应的移植。
    进入qt-everywhere-opensource-src-5.9.6文件夹
    打开 /qtbase/mkspecs/linux-arm-gnueabi-g++/qmake.conf文件
    Qt5.9.6 ARM平台 移植 交叉编译_第1张图片
    将 “=” 号 右边的编译器替换为自己的交叉编译器(即刚刚配置过环境变量的编译器,根据自身情况修改)。若未配置环境变量则需要在编译器前加上路径。
    同时QMAKE_INCDIR 指定为交叉编译完成的tslib和sqlite的头文件路径(空格分隔)
    QMAKE_LIBDIR指定为交叉编译完成后的tslib和sqlite的库文件路径

  2. 运行configure脚本

    ./configure 执行脚本添加参数,这里使用了一个脚本来配置configure,以便于了解参数和日后查看。

./configure \
-v \
##指定编译出来的文件路径
-prefix /home/zzl/arm2/qt5.9.6 \
-confirm-license \
-opensource \
-shared \
-release  \
-make libs \
##指定目标编译平台(实质上是指定/qtbase/mkspecs下的文件夹)
-xplatform linux-arm-gnueabi-g++ \
-optimized-qmake \
-pch \
-linuxfb \
-qt-libjpeg \
-qt-libpng \
##集成sqlite环境
-sqlite \
-qt-zlib \
##不编译集成一下模块(更具自身需求决定)
-no-opengl \
-no-sse2 \
-no-openssl \
-no-cups \
-no-separate-debug-info \
##去掉不必要的样例和工具减少编译时间
-nomake examples -nomake tools -nomake tests -no-iconv \
##集成tslib环境
-tslib \
##指定tslib头文件以及目录
-I/home/zzl/arm2/tslib/include \
-L/home/zzl/arm2/tslib/lib \
-recheck-all 

configure脚本运行过后会打印 组建信息,我保存了下来以供参考

Building on: linux-g++ (x86_64, CPU features: mmx sse sse2)
Building for: linux-arm-gnueabi-g++ (arm, CPU features: )
Configuration: cross_compile compile_examples enable_new_dtags largefile precompile_header shared rpath release c++11 c++14 c++1z concurrent dbus no-pkg-config 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++1z
  Using ccache ........................... no
  Using gold linker ...................... no
  Using new DTAGS ........................ yes
  Using precompiled headers .............. yes
  Using LTCG ............................. no
  Target compiler supports:
    NEON ................................. no
  Build parts ............................ libs
Qt modules and options:
  Qt Concurrent .......................... yes
  Qt D-Bus ............................... yes
  Qt D-Bus directly linked to libdbus .... no
  Qt Gui ................................. yes
  Qt Network ............................. yes
  Qt Sql ................................. yes
  Qt Testlib ............................. yes
  Qt Widgets ............................. yes
  Qt Xml ................................. yes
Support enabled for:
  Using pkg-config ....................... no
  QML debugging .......................... yes
  udev ................................... no
  Using system zlib ...................... no
Qt Core:
  DoubleConversion ....................... yes
    Using system DoubleConversion ........ no
  GLib ................................... no
  iconv .................................. no
  ICU .................................... no
  Logging backends:
    journald ............................. no
    syslog ............................... no
    slog2 ................................ no
  Using system PCRE2 ..................... no
Qt Network:
  getaddrinfo() .......................... yes
  getifaddrs() ........................... yes
  IPv6 ifname ............................ yes
  libproxy ............................... no
  OpenSSL ................................ no
    Qt directly linked to OpenSSL ........ no
  SCTP ................................... no
  Use system proxies ..................... yes
Qt Gui:
  Accessibility .......................... yes
  FreeType ............................... yes
    Using system FreeType ................ no
  HarfBuzz ............................... yes
    Using system HarfBuzz ................ no
  Fontconfig ............................. no
  Image formats:
    GIF .................................. yes
    ICO .................................. yes
    JPEG ................................. yes
      Using system libjpeg ............... no
    PNG .................................. yes
      Using system libpng ................ no
  EGL .................................... no
  OpenVG ................................. no
  OpenGL:
    Desktop OpenGL ....................... no
    OpenGL ES 2.0 ........................ no
    OpenGL ES 3.0 ........................ no
    OpenGL ES 3.1 ........................ no
  Session Management ..................... yes
Features used by QPA backends:
  evdev .................................. yes
  libinput ............................... no
  INTEGRITY HID .......................... no
  mtdev .................................. no
  tslib .................................. yes
  xkbcommon-evdev ........................ no
QPA backends:
  DirectFB ............................... no
  EGLFS .................................. no
  LinuxFB ................................ yes
  VNC .................................... yes
  Mir client ............................. no
Qt Widgets:
  GTK+ ................................... no
  Styles ................................. Fusion Windows
Qt PrintSupport:
  CUPS ................................... no
Qt Sql:
  DB2 (IBM) .............................. no
  InterBase .............................. no
  MySql .................................. no
  OCI (Oracle) ........................... no
  ODBC ................................... no
  PostgreSQL ............................. no
  SQLite2 ................................ no
  SQLite ................................. yes
    Using system provided SQLite ......... yes
  TDS (Sybase) ........................... no
Qt SerialBus:
  Socket CAN ............................. yes
  Socket CAN FD .......................... yes
QtXmlPatterns:
  XML schema support ..................... yes
Qt QML:
  QML interpreter ........................ yes
  QML network support .................... 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
  Path support ........................... yes
  PathView item .......................... yes
  Positioner items ....................... yes
  ShaderEffect item ...................... yes
  Sprite item ............................ yes
Qt Gamepad:
  SDL2 ................................... no
Qt 3D:
  Assimp ................................. yes
  System Assimp .......................... no
  Output Qt3D Job traces ................. no
  Output Qt3D GL traces .................. no
Qt 3D GeometryLoaders:
  Autodesk FBX ........................... no
Qt Wayland Client ........................ no
Qt Wayland Compositor .................... no
Qt Bluetooth:
  BlueZ .................................. no
  BlueZ Low Energy ....................... no
  Linux Crypto API ....................... no
Qt Sensors:
  sensorfw ............................... no
Qt Quick Controls 2:
  Styles ................................. Default 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:
  Geoservice plugins:
    OpenStreetMap ........................ yes
    HERE ................................. yes
    Esri ................................. yes
    Mapbox ............................... yes
    MapboxGL ............................. no
    Itemsoverlay ......................... yes
Qt Multimedia:
  ALSA ................................... no
  GStreamer 1.0 .......................... no
  GStreamer 0.10 ......................... no
  Video for Linux ........................ yes
  OpenAL ................................. no
  PulseAudio ............................. no
  Resource Policy (libresourceqt5) ....... no
  Windows Audio Services ................. no
  DirectShow ............................. no
  Windows Media Foundation ............... no
Qt WebEngine:
  Embedded build ......................... yes
  Pepper Plugins ......................... no
  Printing and PDF ....................... no
  Proprietary Codecs ..................... no
  Spellchecker ........................... yes
  WebRTC ................................. no
  Using system ninja ..................... no
  ALSA ................................... no
  PulseAudio ............................. no
  System libraries:
    re2 .................................. no
    ICU .................................. no
    libwebp and libwebpdemux ............. no
    Opus ................................. no
    ffmpeg ............................... no
  1. 编译和安装
    脚本执行结束后会产生一个Makefile文件,这样就可以开始编译了。
    终端执行make -j4 然后make install
    make install 之后会在你刚刚./configure时指定的目录下生成目标文件。
    Qt5.9.6 ARM平台 移植 交叉编译_第2张图片
    将生成的文件夹拷贝至开发板。
    之后添加环境变量:
    在/etc/profile文件中添加路径:
	##指定Qt lib下的动态库
	export LD_LIBRARY_PATH=/opt/Qt5.9.6/lib
	##指定Qt下的插件
	export QT_QPA_PLATFORM_PLUGIN_PATH=/opt/Qt5.9.6/plugins
	##指定屏幕的设备文件
	export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb0
	##指定Qt的字体库(可以自行添加)
	export QT_QPA_FONTDIR=/opt/Qt5.9.6/lib/fonts

这样Qt的移植就大功告成了。

之后Qt creator进行嵌入式软件开发时指定qmake为编译出来的/qt5.9.6/bin/qmake就可以完成编译了。

你可能感兴趣的:(嵌入式)