Ubuntu18.04实现Aarch64和arm32的穿插编译全步骤(含Qt5.12.10源码编译)

本文所应用的文件下载:

百度网盘:

链接:https://pan.baidu.com/s/1mnpFepFY-rOlwWd3QbYZiw
提取码:5566

下载穿插编译链接工具

)

装置穿插编译器

解压

sudo tar -xvf gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar -C /opt/sudo tar -xvf gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar -C /opt/

解压实现后,配置环境变量

sudo vim ~/.bashrc

增加编译器门路:门路为你解压后门路,我的门路为:/opt/

PATH=$PATH:/opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/binPATH=$PATH:/opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin

配置失效

source ~/.bashrc

验证是否装置胜利

aarch64-linux-gnu-gcc -varm-linux-gnueabihf-gcc -v

arm32如下为胜利。

aarch64如下为胜利

测试穿插编译器

写一个简略的c程序,穿插编译后放到开发板下来运行看看 是否运行胜利

#include <stdio.h>int main(int argc, char **argv){    printf("Hello, you do it succeed!!!\n");    return 0;}
  • 先应用arm32编译

编译实现后,看到文件是32位的。

移植到arm32板子上,能够运行胜利。

  • aarch64编译

编译实现后,看到文件是arm 64位的。

移植到aarch64的板子上,能够运行胜利。

由此可见,两种穿插编译工具都装置胜利,能够应用。

编译Qt源码

这里只是用aarch64编译器去编译qt源码

下载Qt源码

解压qt源码

sudo tar xvf qt-everywhere-src-5.12.10.tar.xzcd  qt-everywhere-src-5.12.10

批改qmake配置文件

首先复制一份文件

sudo cp -a linux-aarch64-gnu-g++/ aarch64-linux-gnu-g++/

批改配置文件目录,前面都改成你穿插编译器装置的门路。”/opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/“

# modifications to g++.confQMAKE_CC                = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc QMAKE_CXX               = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ QMAKE_LINK              = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ QMAKE_LINK_SHLIB        = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ # modifications to linux.confQMAKE_AR                = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-ar cqsQMAKE_OBJCOPY           = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-objcopyQMAKE_NM                = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc-nm  -PQMAKE_STRIP             = /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-stripload(qt_config)

# modifications to g++.confQMAKE_CC                = /opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabi-gccQMAKE_CXX               = /opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabi-g++QMAKE_LINK              = /opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabi-g++QMAKE_LINK_SHLIB        = /opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabi-g++# modifications to linux.confQMAKE_AR                = /opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabi-ar cqsQMAKE_OBJCOPY           = /opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabi-objcopyQMAKE_NM                = /opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabi-nm -PQMAKE_STRIP             = /opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabi-strip

配置编译参数

Linux 下 qt5的装置及库编译(1)_hrx-@@-CSDN博客

qt5的configure选项阐明(2)_hrx-@@-CSDN博客

  1. 倡议是新建一个build目录,而后在该目录下配置configure,make之类的,这样子配置编译生成的临时文件会放在该目录下,而不会污染源码。
  2. 在build目录下创立一个build.sh的脚本,增加如下内容
../qt-everywhere-src-5.12.10/configure \-verbose \-opensource \-release \-shared \-confirm-license \-make libs \-nomake tests \-nomake examples \-skip qtmacextras \-skip qtandroidextras \-no-opengl \-xplatform aarch64-linux-gnu-g++ \-prefix /opt/qt-5.12.10-linux-aarch64-gcc

verbose:打印配置过程中步骤信息
opensource:编译Qt的开源版本
release:编译Qt的release版本
shared:构建 Qt 共享库
confirm-license:主动确认许可
make libs:编译 lib 组件
nomake tests:不编译 tests组件
nomake examples:不编译 examples 组件
skip qtmacextras:跳过 qtmacextras 模块
skip qtandroidextras:跳过 qtandroidextras 模块

no-opengl: 我在虚拟机下编译opengl模块报错,未解决 所以抉择不编译

xplatform: 抉择穿插编译时的指标 mkspec

prefix :指定 make install 的地位

./configure -release -opensource -confirm-license -xplatform aarch64-linux-gnu-gcc  -prefix /opt/aarch64—qt5 -nomake examples -nomake tools -nomake tests -no-opengl

装置编译所依赖的库

  • 装置根底的编译环境
sudo apt-get build-dep qt5-defaultsudo apt-get install libxcb-xinerama0-dev sudo apt-get install build-essential perl python git
  • Libxcb

    sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev
  • OpenGL

    sudo apt-get install build-essentialsudo apt-get install libgl1-mesa-devsudo apt-get install libglu1-mesa-devsudo apt-get install libegl1-mesa-devsudo apt-get install freeglut3-dev
  • Qt WebKit

    sudo apt-get install flex bison gperf libicu-dev libxslt-dev ruby
  • Qt WebEngine

    sudo apt-get install libssl-dev libxcursor-dev libxcomposite-dev libxdamage-dev libxrandr-dev libdbus-1-dev libfontconfig1-dev libcap-dev libxtst-dev libpulse-dev libudev-dev libpci-dev libnss3-dev libasound2-dev libxss-dev libegl1-mesa-dev gperf bison
  • Qt Multimedia

    sudo apt-get install libasound2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
  • QDoc Documentation Generator Tool

    sudo apt install libclang-6.0-dev llvm-6.0

执行build脚本 构建选项:

Build options:  Mode ................................... release  Optimize release build for size ........ no  Building shared libraries .............. yes  Using C standard ....................... C11  Using C++ standard ..................... C++1z  Using ccache ........................... no  Using gold linker ...................... yes  Using new DTAGS ........................ yes  Using precompiled headers .............. yes  Using LTCG ............................. no  Target compiler supports:    SSE .................................. SSE2 SSE3 SSSE3 SSE4.1 SSE4.2    AVX .................................. AVX AVX2    AVX512 ............................... F ER CD PF DQ BW VL IFMA VBMI    Other x86 ............................ AES F16C RDRAND SHA    Intrinsics without -mXXX option ...... yes  Build parts ............................ libsQt 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 ................................. yesSupport enabled for:  Using pkg-config ....................... yes  udev ................................... yes  Using system zlib ...................... yesQt Core:  DoubleConversion ....................... yes    Using system DoubleConversion ........ no  GLib ................................... yes  iconv .................................. no  ICU .................................... yes  Tracing backend ........................ <none>  Logging backends:    journald ............................. no    syslog ............................... no    slog2 ................................ no  Using system PCRE2 ..................... noQt 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  SCTP ................................... no  Use system proxies ..................... yesQt 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 ............... no    PNG .................................. yes      Using system libpng ................ yes  EGL .................................... yes  OpenVG ................................. no  OpenGL:    Desktop OpenGL ....................... yes    OpenGL ES 2.0 ........................ no    OpenGL ES 3.0 ........................ no    OpenGL ES 3.1 ........................ no    OpenGL ES 3.2 ........................ no  Vulkan ................................. no  Session Management ..................... yesFeatures used by QPA backends:  evdev .................................. yes  libinput ............................... no  INTEGRITY HID .......................... no  mtdev .................................. no  tslib .................................. no  xkbcommon .............................. yes  X11 specific:    XLib ................................. yes    XCB Xlib ............................. yes    EGL on X11 ........................... yesQPA 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 ............................ no    EGLFS VSP2 ........................... no    EGLFS Mali ........................... no    EGLFS Raspberry Pi ................... no    EGLFS X11 ............................ yes  LinuxFB ................................ yes  VNC .................................... yes  Mir client ............................. no  XCB:    Using system-provided XCB libraries .. yes    XCB XKB .............................. yes    XCB XInput ........................... yes    Native painting (experimental) ....... yes    GL integrations:      GLX Plugin ......................... yes        XCB GLX .......................... yes      EGL-X11 Plugin ..................... yesQt Sql:  SQL item models ........................ yesQt Widgets:  GTK+ ................................... no  Styles ................................. Fusion WindowsQt PrintSupport:  CUPS ................................... noQt 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) ........................... noQt Testlib:  Tester for item models ................. yesQt SerialBus:  Socket CAN ............................. yes  Socket CAN FD .......................... yesFurther Image Formats:  JasPer ................................. no  MNG .................................... no  TIFF ................................... yes    Using system libtiff ................. no  WEBP ................................... yes    Using system libwebp ................. noQt 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 ..................... yesQt 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 ............................ yesQt Scxml:  ECMAScript data model for QtScxml ...... yesQt Gamepad:  SDL2 ................................... noQt 3D:  Assimp ................................. yes  System Assimp .......................... no  Output Qt3D Job traces ................. no  Output Qt3D GL traces .................. no  Use SSE2 instructions .................. yes  Use AVX2 instructions .................. no  Aspects:    Render aspect ........................ yes    Input aspect ......................... yes    Logic aspect ......................... yes    Animation aspect ..................... yes    Extras aspect ........................ yesQt 3D Renderers:  OpenGL Renderer ........................ yesQt 3D GeometryLoaders:  Autodesk FBX ........................... noQt Wayland Drivers:  EGL .................................... yes  Raspberry Pi ........................... no  XComposite EGL ......................... yes  XComposite GLX ......................... yes  DRM EGL ................................ yes  libhybris EGL .......................... no  Linux dma-buf server buffer integration . yes  Vulkan-based server buffer integration . no  Shm emulation server buffer integration . yesQt Wayland Client ........................ yesQt Wayland Compositor .................... yesQt Wayland Compositor Layer Plugins:  VSP2 hardware layer integration ........ noQt Bluetooth:  BlueZ .................................. no  BlueZ Low Energy ....................... no  Linux Crypto API ....................... no  WinRT Bluetooth API (desktop & UWP) .... noQt Sensors:  sensorfw ............................... noQt Quick Controls 2:  Styles ................................. Default Fusion Imagine Material UniversalQt Quick Templates 2:  Hover support .......................... yes  Multi-touch support .................... yesQt Positioning:  Gypsy GPS Daemon ....................... no  WinRT Geolocation API .................. noQt Location:  Qt.labs.location experimental QML plugin . yes  Geoservice plugins:    OpenStreetMap ........................ yes    HERE ................................. yes    Esri ................................. yes    Mapbox ............................... yes    MapboxGL ............................. yes    Itemsoverlay ......................... yesQtXmlPatterns:  XML schema support ..................... yesQt Multimedia:  ALSA ................................... yes  GStreamer 1.0 .......................... no  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 ............... noQt Tools:  QDoc ................................... yesQt WebEngine:  Embedded build ......................... no  Full debug information ................. no  Pepper Plugins ......................... yes  Printing and PDF ....................... yes  Proprietary Codecs ..................... no  Spellchecker ........................... yes  Native Spellchecker .................... no  WebRTC ................................. yes  Use System Ninja ....................... no  Geolocation ............................ yes  WebChannel support ..................... yes  Use v8 snapshot ........................ yes  Kerberos Authentication ................ no  Support qpa-xcb ........................ yes  Use ALSA ............................... yes  Use PulseAudio ......................... yes  Optional system libraries used:    re2 .................................. no    icu .................................. no    libwebp, libwebpmux and libwebpdemux . no    opus ................................. no    ffmpeg ............................... no    libvpx ............................... no    snappy ............................... no    glib ................................. yes    zlib ................................. yes    minizip .............................. no    libevent ............................. no    jsoncpp .............................. no    protobuf ............................. no    libxml2 and libxslt .................. yes    lcms2 ................................ no    png .................................. yes    JPEG ................................. no    harfbuzz ............................. yes    freetype ............................. yes  Required system libraries:    fontconfig ........................... yes    dbus ................................. yes    nss .................................. yes    khr .................................. yes    glibc ................................ yes  Required system libraries for qpa-xcb:    x11 .................................. yes    libdrm ............................... yes    xcomposite ........................... yes    xcursor .............................. yes    xi ................................... yes    xtst ................................. yesNote: Also available for Linux: linux-clang linux-iccNote: Disabling X11 Accessibility Bridge: D-Bus or AT-SPI is missing.Qt is now configured for building. Just run 'make'.Once everything is built, you must run 'make install'.Qt will be installed into '/opt/qt-5.12.10-linux-aarch64'.Prior to reconfiguration, make sure you remove any leftovers fromthe previous build.

执行make

对源码进行编译,工夫挺长的,大概三四个小时

make -j8

执行make install

sudo make install

在编译实现后执行 make install 会将qt库装置到 -prefix 指定的目录下。

查看库的零碎架构

能够库装置门路上面,readelf - h xxx.so 能够看到编译进去的库零碎架构是Aarch64的。

配置qtcreator穿插编译环境

在ubuntu下搭建Qt Creator的arm穿插编译环境_bigmarshal的博客-CSDN博客

首先没有装置qtcreator,须要装置

sudo apt-get install qtcreator

增加穿插编译工具链

编译器门路,抉择你之前装置的门路,我的门路为:

c++

/opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++

c

/opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc

抉择qmake版本,门路为你编译输入的门路。

增加Kit

创立个带界面的工程进行穿插编译测试

抉择Aarch64编译

程序依赖库也是失常的。

能够看出编译生成的应用程序是ARM aarch64的。接下来打包后移植到rk3399中执行关上。

最初能够看出功败垂成~~~

疑难?

  1. 如果用rk3399上所有qt的依赖库,再加上qmake和gcc编译工具,不晓得是否能够跳过编译qt源码这个步骤,间接应用现有的依赖库?
  2. 可能间接能够应用他人穿插编译后的依赖库曾经qmake等编译工具?

遇到的问题

编译opengl 模块报错

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: Python version 2 (2.7.5 or later) is required to build QtWebEngine.WARNING: gperf is required to build QtWebEngine.WARNING: bison is required to build QtWebEngine.WARNING: flex is required to build QtWebEngine.WARNING: host pkg-config not foundERROR: 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.

imx6 qt5编译出错“ QMAKE_INCDIR_OPENGL_ES2, QMAKE_LIBDIR_OPENGL_ES2" - i.MX - 恩智浦技术社区 (nxpic.org.cn)

QMAKE_INCDIR += /usr/include
QMAKE_LIBDIR += /usr/lib

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.

QMAKE_INCDIR_EGL = /usr/include QMAKE_LIBDIR_EGL = /usr/libQMAKE_INCDIR_OPENGL_ES2 = /usr/includeQMAKE_LIBDIR_OPENGL_ES2 = /usr/libQMAKE_LIBS_EGL         += -lEGLQMAKE_LIBS_OPENGL_ES2  += -lGLESv2 -lEGL -lGALQMAKE_INCDIR       += /usr/includeQMAKE_LIBDIR       += /usr/lib

configuring Qt5.15 source on Ubuntu 20.04 opengl necessary for qt-quick - Stack Overflow

sudo ./configure -no-opengl -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=/opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf- -opensource -confirm-license -optimized-qmake -reduce-exports -release -make libs -prefix /opt/qt5_amr32
  • ./configure -release -opengl es2 -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=~/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf- -sysroot ~/raspi/sysroot -opensource -confirm-license -skip qtwayland -skip qtlocation -skip qtscript -make libs -prefix /usr/local/qt5pi -extprefix ~/raspi/qt5pi -hostprefix ~/raspi/qt5 -no-use-gold-linker -v -no-gbm
  • $ ./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