前言:

          项目需要移植qt到arm开发板上,历经千辛万苦解决了各种问题,最后终于成功了,所以整理了开发笔记给更多的小伙伴参考。

1.准备阶段

①下载交叉编译器aarch65-linux-gnu,下载地址为:Linaro Releases

②下载Qt5.9.6源码,下载地址为:Index of /archive/qt/5.9/5.9.6/single

③下载Qtcreator安装包,下载地址为:Index of /archive/qt/5.9/5.9.6

④安装虚拟机VMware® Workstation 14 Pro和Ubuntu16.04.5 LTS,博主的虚拟机版本如下图:

⑤将文件分别存放在相应文件夹下并解压:

****.tar.gz 文件的解压命令是 :tar -zxvf ****.tar.gz

****.tar.xz 文件的解压命令是 :tar xvJf ****.tar.xz

第一步的准备工作已完成。


2. 安装交叉编译器:

交叉编译器解压之后的路径为:/home/admin/Qt_Env/Cross-compiler/

①查看当前环境变量命令:echo $PATH

②在/etc/profile中添加新的环境变量:

  • 执行命令:gedit /etc/profile

  • 在文件末尾添加:export PATH=$PATH:/home/admin/Qt_Env/Cross-compiler/aarch64-linux-gnu/bin

  • 执行命令:source /etc/profile

③再次执行echo $PATH

 

可以看到环境变量已经添加上了。

④验证编译器是否安装成功

  • 执行命令:aarch64-linux-gnu-g++ -v

终端显示编译器信息如下:

编译器安装成功。

注意:在/etc/profile中改变的环境变量是临时的,重启虚拟机或重启终端会导致环境变量修改不生效,所以在编译qt之前一定要确定交叉编译器安装成功,如果执行④打印的是gcc的版本信息,那么可能是编译器路径不对,或者多执行几次source /etc/profile即可。


3.交叉编译qt5.9.6

①配置qt的configure

在目录/home/Qt_Env/Qt_opensource下创建 qt_compiler_conf.sh文件,文件是configure的配置项,关于配置项的说明资料很多,在此不在赘述。

#!/bin/sh  
./configure -prefix /opt/aarch64/qt596_64/qt_sdk \
-opensource \
-debug \
-confirm-license \
-xplatform linux-arm-gnueabi-g++ \
-no-opengl \
-no-pch \
-shared \
-no-iconv \
-no-xcb \

精简版configure:(两个.sh都可以)

#!/bin/bash
 ./configure \
 -prefix ../arm-qt-output \
 -xplatform linux-aarch64-gnu-g++ \
 -no-static \
 -qt-libpng \
 -qt-libjpeg \
 -qt-zlib \
 -no-strip \
 -no-framework \
 -no-sse2 \
 -no-sse3 \
 -no-sse4.1 \
 -no-sse4.2 \
 -no-avx \
 -no-avx2 \
 -no-avx512 \
 -no-mips_dsp \
 -no-mips_dspr2 \
 -no-icu \
 -no-sql-sqlite \
 -no-accessibility \
 -no-ssl \
 -disable-system-proxies \
 -no-cups \
 -no-gtk \
 -no-opengles3 \
 -no-xcb \
 -no-ico \
 -no-opengl \
 -no-eglfs \
 -no-direct2d \
 -no-directfb \
 -no-gbm \
 -no-kms \
 -no-mirclient \
 -no-xcb \
 -no-xkbcommon-evdev \
 -no-xkbcommon-x11 \
 -no-doubleconversion \
 -enable-linuxfb \
 -qt-freetype \
 -make libs \
 -nomake examples \
 -nomake tests \
 -nomake tools \
 -opensource \
 -confirm-license \
 -skip qt3d \
 -skip qtactiveqt \
 -skip qtandroidextras \
 -skip qtcanvas3d \
 -skip qtcharts \
 -skip qtconnectivity \
 -skip qtdatavis3d \
 -skip qtdeclarative \
 -skip qtdoc \
 -skip qtgamepad \
 -skip qtgraphicaleffects \
 -skip qtlocation \
 -skip qtmacextras \
 -skip qtmultimedia \
 -skip qtnetworkauth \
 -skip qtpurchasing \
 -skip qtquickcontrols \
 -skip qtquickcontrols2 \
 -skip qtremoteobjects \
 -skip qtscript \
 -skip qtscxml \
 -skip qtsensors \
 -skip qtserialbus \
 -skip qtserialport \
 -skip qtspeech \
 -skip qtsvg \
 -skip qttools \
 -skip qttranslations \
 -skip qtvirtualkeyboard \
 -skip qtwayland \
 -skip qtwebchannel \
 -skip qtwebengine \
 -skip qtwebglplugin \
 -skip qtwebsockets \
 -skip qtwebview \
 -skip qtwinextras \
 -skip qtxmlpatterns \
 -skip qtx11extras \
 -no-iconv \
 -no-harfbuzz \
 -no-evdev

②修改qmake文件

安装目录打开:/home/hytera/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtbase/mkspecs/linux-arm-gnueabi-g++,打开qmake.conf文件,修改编译器:

#
# qmake configuration for building with arm-linux-gnueabi-g++
#
 
MAKEFILE_GENERATOR      = UNIX
CONFIG                 += incremental
QMAKE_INCREMENTAL_STYLE = sublib
 
include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)

QT_QPA_DEFAULT_PLATFORM=linuxfb
# modifications to g++.conf
QMAKE_CC                = aarch64-linux-gnu-gcc
QMAKE_CXX               = aarch64-linux-gnu-g++
QMAKE_LINK              = aarch64-linux-gnu-g++
QMAKE_LINK_SHLIB        = aarch64-linux-gnu-g++
 
# modifications to linux.conf
QMAKE_AR                = aarch64-linux-gnu-ar cqs
QMAKE_OBJCOPY           = aarch64-linux-gnu-objcopy
QMAKE_NM                = aarch64-linux-gnu-nm -P
QMAKE_STRIP             = aarch64-linux-gnu-strip
load(qt_config)

注意:arm开发板上显示屏的驱动是基于fb的话,记得在文件中添加QT_QPA_DEFAULT_PLATFORM=linuxfb。

③执行qt_compiler_conf.sh配置文件

※ 在终端执行命令:./qt_compiler_conf.sh 

※ 或者,博主将终端打印的日志重定向到了confLog.txt文件中,方便查看,故执行的命令是:./qt_compiler_conf.sh  2>&1 | tee confLog.txt

※ 执行结果为:

+ cd qtbase
+ /home/hytera/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtbase/configure -top-level -prefix /opt/aarch64/qt596_64/qt_sdk -opensource -debug -confirm-license -xplatform linux-arm-gnueabi-g++ -no-opengl -no-pch -shared -no-iconv -xcb
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: linux-arm-gnueabi-g++ (arm64, CPU features: neon)
Configuration: cross_compile compile_examples enable_new_dtags largefile neon optimize_debug shared rpath debug c++11 c++14 c++1z concurrent dbus no-pkg-config reduce_exports release_tools stl
Build options:
  Mode ................................... debug; optimized tools
  Optimize debug build ................... yes
  Building shared libraries .............. yes
  Using C++ standard ..................... C++1z
  Using ccache ........................... no
  Using gold linker ...................... no
  Using new DTAGS ........................ yes
  Using precompiled headers .............. no
  Using LTCG ............................. no
  Target compiler supports:
    NEON ................................. yes
  Build parts ............................ libs examples
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 .................................. no
  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 ......... no
  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

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

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 '/opt/aarch64/qt596_64/qt_sdk'.

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

④执行make并重定向到makeLog.txt

命令为:make -j4 2>&1 | tee makeLog.txt

这个过程时间比较久,根据电脑性能,半个小时到六个小时不等。执行完成后的makeLog.txt如下,可以打开makeLog.txt,检索是否有error,如果没有,那就顺利编译通过啦!!!

-----------------------------------------------------------------------------------------
前面省略26571行
-----------------------------------------------------------------------------------------

make[4]: Leaving directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtnetworkauth/examples/oauth/twittertimeline'
make[3]: Leaving directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtnetworkauth/examples/oauth'
make[2]: Leaving directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtnetworkauth/examples'
make[1]: Leaving directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtnetworkauth'

⑤执行make install安装命令,并重定向到installLog.txt

命令为:make install 2>&1 | tee installLog.txt

installLog.txt的内容如下,打开文件检测是否有error。

-------------------------------------------------------------------------------------------
前面省略13492行
-------------------------------------------------------------------------------------------

make[2]: Leaving directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qttranslations/translations'
make[1]: Leaving directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qttranslations'
cd qtdoc/ && ( test -e Makefile || /home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtbase/bin/qmake -o Makefile /home/hytera/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtdoc/qtdoc.pro ) && make -f Makefile install
make[1]: Entering directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtdoc'
cd doc/ && ( test -e Makefile || /home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtbase/bin/qmake -o Makefile /home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtdoc/doc/doc.pro ) && make -f Makefile install
make[2]: Entering directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtdoc/doc'
make[2]: Nothing to be done for 'install'.
make[2]: Leaving directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtdoc/doc'
make[1]: Leaving directory '/home/admin/Qt_Env/Qt_opensource/qt-everywhere-opensource-src-5.9.6/qtdoc'

       完成这一步,qt编译成功。


4. 将qt移植到arm开发板并运行example程序

   这一部分内容较多,将在博主的另一篇博文中介绍。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐