Qt5.12.11交叉编译+64位ARM_aarch64+全志H5 CortexA53

1、准备工作

     购买的H5开发板,附带资料里面只有关于qt4.8的支持,Qt5新增了很多插件,为了在H5上运行Qt5的程序,需要交叉编译Qt5版本的源码,记录下编译Qt5.12.11版本的源码交叉编译。

硬件:NanoPi K1 Plus,采用H5芯片,ARMv8架构,aarch64指令集。

Qt版本5.12.11:下载地址,https://mirrors.tuna.tsinghua.edu.cn/qt/archive/qt/5.12/5.12.11/single/qt-everywhere-src-5.12.11.tar.xz

虚拟机:Ubuntu20.04LTS 桌面版。

交叉编译器:https://releases.linaro.org/components/toolchain/binaries/6.3-2017.02/aarch64-linux-gnu/

我编译了Qt5.12.9和Qt5.12.11两个版本的源码,方法一样,最后都能运行在开发板上。

2、安装交叉编译工具

    将交叉编译工具压缩包gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu.tar拷贝到虚拟机目录下,我使用的是Xftp这个工具。然后使用tar命令解压缩,然后添加到环境变量中,添加到/etc/profile目录下,使用source  /etc/profile命令,使环境变量生效,然后使用aarch64-linux-gnu-gcc -v命令查看工具是否安装成功,也可以将环境变量添加到当前用户的家目录的的.bashrc目录下。

在/etc/profile文件的最后添加交叉编译工具安装路径,使用source /etc/profile命令生效环境变量。

3、修改qmake.conf文件

      将第一步下载的Qt源码移动到虚拟机中自己新建的文件夹中,我新建的Qt源码存放路径为/opt/qt5.12.11。不同的硬件架构对应不同的qmake.conf,在下载的Qt5.12.11源码中的qtbase/mkspecs/目录下有各种不同的平台,H5使用的是linux-aarch64-gun-g++目录下的qmake配置文件,我们先拷贝一个这个文件的备份,在备份文件中修改qmake.conf。将linux-aarch64-gun-g++这个目录拷贝到与这个文件同一目录下的aarch64目录,如下图所示。

#
# qmake configuration for building with aarch64-linux-gnu-g++
#

MAKEFILE_GENERATOR      = UNIX
CONFIG                 += incremental
QMAKE_INCREMENTAL_STYLE = sublib

QT_QPA_DEFAULT_PLATFORM=linuxfb
QMAKE_CFLAGS_RELEASE += -O2 -march=armv8-a -lts
QMAKE_CXXFLAGS_RELEASE += -O2 -march=armv8-a -lts


include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)

# modifications to g++.conf
QMAKE_CC                =/usr/local/arm/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc
QMAKE_CXX               =/usr/local/arm/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++
QMAKE_LINK              =/usr/local/arm/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++
QMAKE_LINK_SHLIB        =/usr/local/arm/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++

# modifications to linux.conf
QMAKE_AR                =/usr/local/arm/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-ar cqs
QMAKE_OBJCOPY           =/usr/local/arm/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-objcopy
QMAKE_NM                =/usr/local/arm/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-nm -P
QMAKE_STRIP             =/usr/local/arm/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-strip
load(qt_config)

上图为Qt源码文件夹中qtbase/mkspecs/aarch64/qmake.conf文件内容。为了避免修改错误aarch64为拷贝的qtbase/mkspecs/aarch64/linux-aarch64-gun-g++文件。

4、配置编译选项

在解压的Qt5.12.11源码目录下使用./configure -help命令,可以查看编译配置选项。一般将需要编译的内容添加到一个shell脚本中,在源码的顶层目录下新增autoconfigure.sh这个文件的名称可以随便定义。下面为文件的内容。

./configure -prefix /opt/qt5.12.11/qt/arm-qt \     这个路径是我们自己新建的目录,编译后的文件就会在这个目录下面,如果拷贝时需要删除汉字的注释
	-opensource -confirm-license \
	-release \
	-strip \
	-shared \
	-xplatform aarch64 \      这是我们之前修改的qmake.conf文件的目录名称,如果需要拷贝需要删除汉字注释
	-optimized-qmake \
	-c++std c++11 \
	--rpath=no \
	-pch \
	-skip qt3d \
	-skip qtactiveqt \
	-skip qtandroidextras \
	-skip qtcanvas3d \
	-skip qtconnectivity \
	-skip qtdatavis3d \
	-skip qtdoc \
	-skip qtgamepad \
	-skip qtlocation \
	-skip qtmacextras \
	-skip qtnetworkauth \
	-skip qtpurchasing \
	-skip qtremoteobjects \
	-skip qtscript \
	-skip qtscxml \
	-skip qtsensors \
	-skip qtspeech \
	-skip qtsvg \
	-skip qttools \
	-skip qttranslations \
	-skip qtwayland \
	-skip qtwebengine \
	-skip qtwebview \
	-skip qtwinextras \
	-skip qtx11extras \
	-skip qtxmlpatterns \
	-make libs \
	-make examples \
	-nomake tools -nomake tests \
	-gui \
	-widgets \
	-dbus-runtime \
	--glib=no \
	--iconv=no \
	--pcre=qt \
	--zlib=qt \
	-no-openssl \
	--freetype=qt \
	--harfbuzz=qt \
	-no-opengl \
	-linuxfb \
	--xcb=no \
	--libpng=qt \
	--libjpeg=qt \
	--sqlite=qt \
	-plugin-sql-sqlite \
	-recheck-all

在autoconfigure.sh中添加上面的内容后,给文件使用chmod 777 autoconfigure.sh给文件添加执行的权限,然后运行./autoconfigure,生成makefile文件。

如果配置编译选项没有错误,运行了autoconfigure.sh文件后没有错误就会出现类似上图的显示,如果没有出现,可能是autoconfigure.sh文件错误,我当时也是拷贝的别人的文件,结果很多不能被识别的字符,格式需要注意。

5、make

运行了.autocinfigure.sh文件后,就可以执行make命令了。根据机器的配置不同,不同的机器make的时间不同。我使用time (make -j16)命令执行make,time可以测试make所消耗的时间。

6、make install

make完成后就可以执行make install命令了,make install命令执行完之后就能在我们新建的arm-qt目录下面生成在可以再我们目标开发板上运行的qt环境了,将这个arm-qt文件,全部拷贝到目标开发板上,然后添加qt5运行的环境就能运行qt5的程序了。

上图中显示的目录就是我们最后编译出来的文件,将这个文件夹拷贝到开发板中,我使用的是nfs方式拷贝到开发板的。

7、开发板中运行

上图是通过串口与开发板通信,显示的目录为之前编译出来的arm-qt目录。在开发板的/etc/profile文件的最后添加Qt运行的环境变量。

export QT_ROOT=/usr/lib/arm-qt  #虚拟机中编译出来的arm-qt文件,根据自己的目录来填写
export QT_QPA_FONTDIR=/usr/share/fonts #字体的目录,如果Qt中有中文显示,需要拷贝电脑C盘中的字体文件到这个目录下面
export QT_QPA_PLATFORM_PLUGIN_PATH=$QT_ROOT/plugins#Qt支持的插件
export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb0
export QT_PLUGIN_PATH=$QT_ROOT/plugins
export LD_LIBRARY_PATH=$QT_ROOT/lib:$QT_ROOT/plugins/platforms
export QML2_IMPORT_PATH=$QT_ROOT/qml

我的开发板没有触摸的显示屏,我使用的是HDMI接口连接的显示器,现在我们可以运行编译出来的目录下面的examples下面的文件,现在运行下图目录下的文件。

上图就是运行/arm-qt/examples/widgets/animation/animatedtiles目录下的animatedtiles可执行文件。上图

上图是运行arm-qt/examples/charts/areachart目录下的areachart可执行文件后的效果。

开发板的Qt5环境就搭建好了,就可以在Ubuntu下面使用QtCreator编写Qt程序,然后使用我们编译出来的qmke及交叉编译工具编译开发板上能运行的程序了,下一天记录下载Ubuntu20.4下面编写一个简单的程序,然后运行在开发板上的例子。下面是我的开发板。

如果有问题欢迎大家一起讨论,谢谢大家的支持。

  • 10
    点赞
  • 86
    收藏
    觉得还不错? 一键收藏
  • 23
    评论
Building on: linux-g++ (x86_64, CPU features: mmx sse sse2) Building for: linux-aarch64-gnu-g++ (arm64, CPU features: neon) Target compiler: gcc 6.3.1 Configuration: cross_compile use_gold_linker compile_examples enable_new_dtags largefile neon precompile_header shared rpath release c++11 c++14 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++14 Using ccache ........................... no Using gold linker ...................... yes Using new DTAGS ........................ 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 .... 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 ....................... yes udev ................................... no Using system zlib ...................... yes Qt Core: DoubleConversion ....................... yes Using system DoubleConversion ........ no GLib ................................... no iconv .................................. yes ICU .................................... no Tracing backend ........................ Logging backends: journald ............................. no syslog ............................... no slog2 ................................ no 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 ............................ no DTLS ................................... yes 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 ............... yes 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 OpenGL ES 3.2 ........................ no Vulkan ................................. no Session Management ..................... yes Features used by QPA backends: evdev .................................. yes libinput ............................... no INTEGRITY HID .......................... no mtdev .................................. no tslib .................................. no xkbcommon .............................. no X11 specific: XLib ................................. no EGL on X11 ........................... no QPA backends: DirectFB ............................... no EGLFS .................................. no LinuxFB ................................ yes VNC .................................... yes Mir client ............................. no 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 ............................. no SQLite2 ................................ no SQLite ................................. yes Using system provided SQLite ......... no TDS (Sybase) ........................... no Qt Testlib: Tester for item models ................. yes Qt SerialBus: Socket CAN ............................. yes Socket CAN FD .......................... yes Qt QML: QML network support .................... yes QML debugging and profiling support .... yes QML sequence object .................... yes QML list model ......................... yes QML XML http request ................... yes QML Locale ............................. 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 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 Wayland Client ........................ no Qt Wayland Compositor .................... no Qt Bluetooth: BlueZ .................................. no BlueZ Low Energy ....................... no Linux Crypto API ....................... no WinRT Bluetooth 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 ............................. no Itemsoverlay ......................... yes QtXmlPatterns: XML schema support ..................... 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 Tools: QDoc ................................... no Qt WebEngine: Embedded build ......................... yes Pepper Plugins ......................... no Printing and PDF ....................... no Proprietary Codecs ..................... no Spellchecker ........................... yes Native Spellchecker .................... no WebRTC ................................. no Use System Ninja ....................... no Geolocation ............................ yes WebChannel support ..................... yes Use v8 snapshot ........................ yes Kerberos Authentication ................ no Building v8 snapshot supported ......... yes Use ALSA ............................... no Use PulseAudio ......................... no Optional system libraries used: re2 .................................. no icu .................................. no libwebp, libwebpmux and libwebpdemux . no opus ................................. no ffmpeg ............................... no libvpx ............................... no snappy ............................... no glib ................................. no zlib ................................. yes minizip .............................. no libevent ............................. no jsoncpp .............................. no protobuf ............................. no libxml2 and libxslt .................. no lcms2 ................................ no png .................................. no JPEG ................................. no harfbuzz ............................. no freetype ............................. no x11 .................................. no Required system libraries: fontconfig ........................... no dbus ................................. no nss .................................. no khr .................................. no glibc ................................ yes Required system libraries for qpa-xcb: libdrm ............................... no xcomposite ........................... no xcursor .............................. no xi ................................... no xrandr ............................... no xtst ................................. no Note: Also available for Linux: linux-clang linux-icc
评论 23
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值