交叉编译Qt5.12.8附带编译opengl

打印 上一主题 下一主题

主题 886|帖子 886|积分 2658

提示:文章写完后,目次可以主动生成,如何生成可参考右边的帮助文档
  
  

前言

近来有个项目使用Qt5的ARM64版,有一种方法是直接在板子上安装Qt5,这种方法最简朴,但是板子服从低一些,编译慢,画面也不太流畅以是才切换到交叉编译方向来。
这篇文章基于Ubuntu-20.04编译,板子的体系也是20.04,接下来我会给出我的编译心得,包括一些留意事项,请仔细查察,能少走不少弯路。
OS:Ubuntu-20.04 x86_64
Board:Ubuntu-20.04 aarch64
工具:aarch64-linux-gnu-9

一、重要说明

最好板子的情况和OS的情况一样,如许可以避免不须要的报错,而且由于Qt5程序依赖libc这个库,导致高版本体系编译的二进制文件放在低版本体系不能运行。
为什么选择aarch64-linux-gnu-9,因为高版本可能出现不兼容的现象,报各种错,以是建议编译器版本不要超过9,9也是可以的。
留意:这个教程5.12.8版本一次编译通过,5.15.2可能报错,QT6也不确定是否能用!
二、预备情况

1.下载qt5.12.8源代码

5.12.8下载页面
zip和tar.xz都行,只不外xz压缩率更高,建议选xz

2.配置体系情况

  1. sudo apt update
  2. sudo apt install g++-9-aarch64-linux-gnu gcc-9-aarch64-linux-gnu cmake gdb clang
复制代码
3.安装须要工具

  1. sudo apt install qtbase5-dev qt5-qmake qtcreator
复制代码
4.解压qt5源代码

  1. tar -xmf qt-everywhere-src-5.12.8.tar.xz
复制代码
5.开始配置编译

  1. ./configure -release -opensource -confirm-license -xplatform linux-aarch64-gnu-g++ -prefix ~/Qt5.12.8_ARM64 -nomake examples -no-opengl -silent -qpa linuxfb
复制代码
留意:这个版本不带opengl,假如你用不到opengl就可以不编译,假如你用opengl就要用另一种方法,下面会说。
这种方法可能不会编译web引擎,假如你用不到可以不消管,假如你用的到就按照它的提示追加就行了。等qmake构建好之后就可以编译了,留意使用的线程数。
  1. make -j6 && make install
复制代码
6.配置qtcreator

上面已经安装好qtcreator了,打开开始配置交叉编译情况。
打开Tools->Options

Kits->Qt Versions

右边的Add会打开一个文件管理器。

找到我们编译好的Qt5.12.8_ARM64直到bin/qmake,选中打开就会添加新情况。


接着打开Kits条目,同样右边的Add

Name:随便取
Device type:和我一样
Device:和我一样
Sysroot:留空
Compiler:按照我的,肯定不要错了,选刚刚安装的arm 64bit
Debuger:gdb
Qt version:和我一样,选刚才添加的

Cmake Tool:选cmake就行了
最终Apply->Ok。
创建一个新项目或旧项目选择ARM64就可以交叉编译了,目前这个方法不能在x86_64上运行,你需要把二进制文件拷贝到aarch64设备上运行。
三、编译opengl

上面的方法没有opengl的支持,现实上我试了很多方法单纯在x86_64上编译opengl是不行的,需要借助sysroot,可以理解成你板子的rootfs。
你先去板子官方找一个rootfs,安装配置好opengl情况,背面要用。这里以firefly的rk3399为例,我把rootfs拷贝到我的Ubuntu-20.04电脑上了。

这个rootfs是可以通过qemu-user-static软件模拟情况的,这个就不细说了,一样寻常支持定制的板子厂商的维基里都会说明的。
上面的软件照样装,流程照样走一边,只是到了构建的时候命令变了:
  1. ./configure -sysroot ~/firefly-rk3399-ubuntu2004-rootfs -release -opensource -confirm-license -xplatform linux-aarch64-gnu-g++ -extprefix ~/Qt5.12.8_ARM64 -nomake examples -opengl -silent -qpa linuxfb
复制代码
-sysroot:指定你自己的rootfs目次
-extprefix:这个叫外部安装路径,要否则编译好的安装到rootfs里面去了
-opengl:指定编译opengl Desktop,根据自己需要编译
等待构建完成…
贴下我的构建输出:
  1. Building on: linux-g++ (x86_64, CPU features: mmx sse sse2)
  2. Building for: linux-aarch64-gnu-g++ (arm64, CPU features: cx16 neon)
  3. Target compiler: gcc 9.4.0
  4. Configuration: cross_compile use_gold_linker compile_examples enable_new_dtags largefile neon precompile_header silent shared rpath release c++11 c++14 c++1z concurrent dbus reduce_exports stl
  5. Build options:
  6.   Mode ................................... release
  7.   Optimize release build for size ........ no
  8.   Building shared libraries .............. yes
  9.   Using C standard ....................... C11
  10.   Using C++ standard ..................... C++1z
  11.   Using ccache ........................... no
  12.   Using gold linker ...................... yes
  13.   Using new DTAGS ........................ yes
  14.   Using precompiled headers .............. yes
  15.   Using LTCG ............................. no
  16.   Target compiler supports:
  17.     NEON ................................. yes
  18.   Build parts ............................ libs
  19. Qt modules and options:
  20.   Qt Concurrent .......................... yes
  21.   Qt D-Bus ............................... yes
  22.   Qt D-Bus directly linked to libdbus .... no
  23.   Qt Gui ................................. yes
  24.   Qt Network ............................. yes
  25.   Qt Sql ................................. yes
  26.   Qt Testlib ............................. yes
  27.   Qt Widgets ............................. yes
  28.   Qt Xml ................................. yes
  29. Support enabled for:
  30.   Using pkg-config ....................... yes
  31.   udev ................................... no
  32.   Using system zlib ...................... yes
  33. Qt Core:
  34.   DoubleConversion ....................... yes
  35.     Using system DoubleConversion ........ no
  36.   GLib ................................... no
  37.   iconv .................................. yes
  38.   ICU .................................... no
  39.   Tracing backend ........................ <none>
  40.   Logging backends:
  41.     journald ............................. no
  42.     syslog ............................... no
  43.     slog2 ................................ no
  44.   Using system PCRE2 ..................... no
  45. Qt Network:
  46.   getifaddrs() ........................... yes
  47.   IPv6 ifname ............................ yes
  48.   libproxy ............................... no
  49.   Linux AF_NETLINK ....................... yes
  50.   OpenSSL ................................ no
  51.     Qt directly linked to OpenSSL ........ no
  52.   OpenSSL 1.1 ............................ no
  53.   DTLS ................................... no
  54.   SCTP ................................... no
  55.   Use system proxies ..................... yes
  56. Qt Gui:
  57.   Accessibility .......................... yes
  58.   FreeType ............................... yes
  59.     Using system FreeType ................ no
  60.   HarfBuzz ............................... yes
  61.     Using system HarfBuzz ................ no
  62.   Fontconfig ............................. no
  63.   Image formats:
  64.     GIF .................................. yes
  65.     ICO .................................. yes
  66.     JPEG ................................. yes
  67.       Using system libjpeg ............... no
  68.     PNG .................................. yes
  69.       Using system libpng ................ no
  70.   EGL .................................... yes
  71.   OpenVG ................................. no
  72.   OpenGL:
  73.     Desktop OpenGL ....................... yes
  74.     OpenGL ES 2.0 ........................ no
  75.     OpenGL ES 3.0 ........................ no
  76.     OpenGL ES 3.1 ........................ no
  77.     OpenGL ES 3.2 ........................ no
  78.   Vulkan ................................. no
  79.   Session Management ..................... yes
  80. Features used by QPA backends:
  81.   evdev .................................. yes
  82.   libinput ............................... no
  83.   INTEGRITY HID .......................... no
  84.   mtdev .................................. no
  85.   tslib .................................. no
  86.   xkbcommon .............................. yes
  87.   X11 specific:
  88.     XLib ................................. yes
  89.     XCB Xlib ............................. yes
  90.     EGL on X11 ........................... yes
  91. QPA backends:
  92.   DirectFB ............................... no
  93.   EGLFS .................................. yes
  94.   EGLFS details:
  95.     EGLFS OpenWFD ........................ no
  96.     EGLFS i.Mx6 .......................... no
  97.     EGLFS i.Mx6 Wayland .................. no
  98.     EGLFS RCAR ........................... no
  99.     EGLFS EGLDevice ...................... no
  100.     EGLFS GBM ............................ no
  101.     EGLFS VSP2 ........................... no
  102.     EGLFS Mali ........................... no
  103.     EGLFS Raspberry Pi ................... no
  104.     EGLFS X11 ............................ yes
  105.   LinuxFB ................................ yes
  106.   VNC .................................... yes
  107.   Mir client ............................. no
  108.   XCB:
  109.     Using system-provided XCB libraries .. no
  110.     XCB XKB .............................. yes
  111.     XCB XInput ........................... yes
  112.     Native painting (experimental) ....... no
  113.     GL integrations:
  114.       GLX Plugin ......................... yes
  115.         XCB GLX .......................... no
  116.       EGL-X11 Plugin ..................... yes
  117. Qt Sql:
  118.   SQL item models ........................ yes
  119. Qt Widgets:
  120.   GTK+ ................................... no
  121.   Styles ................................. Fusion Windows
  122. Qt PrintSupport:
  123.   CUPS ................................... no
  124. Qt Sql Drivers:
  125.   DB2 (IBM) .............................. no
  126.   InterBase .............................. no
  127.   MySql .................................. no
  128.   OCI (Oracle) ........................... no
  129.   ODBC ................................... no
  130.   PostgreSQL ............................. no
  131.   SQLite2 ................................ no
  132.   SQLite ................................. yes
  133.     Using system provided SQLite ......... no
  134.   TDS (Sybase) ........................... no
  135. Qt Testlib:
  136.   Tester for item models ................. yes
  137. Qt SerialBus:
  138.   Socket CAN ............................. yes
  139.   Socket CAN FD .......................... yes
  140. Further Image Formats:
  141.   JasPer ................................. no
  142.   MNG .................................... no
  143.   TIFF ................................... yes
  144.     Using system libtiff ................. no
  145.   WEBP ................................... yes
  146.     Using system libwebp ................. no
  147. Qt QML:
  148.   QML network support .................... yes
  149.   QML debugging and profiling support .... yes
  150.   QML sequence object .................... yes
  151.   QML list model ......................... yes
  152.   QML XML http request ................... yes
  153.   QML Locale ............................. yes
  154.   QML delegate model ..................... yes
  155. Qt Quick:
  156.   Direct3D 12 ............................ no
  157.   AnimatedImage item ..................... yes
  158.   Canvas item ............................ yes
  159.   Support for Qt Quick Designer .......... yes
  160.   Flipable item .......................... yes
  161.   GridView item .......................... yes
  162.   ListView item .......................... yes
  163.   TableView item ......................... yes
  164.   Path support ........................... yes
  165.   PathView item .......................... yes
  166.   Positioner items ....................... yes
  167.   Repeater item .......................... yes
  168.   ShaderEffect item ...................... yes
  169.   Sprite item ............................ yes
  170. Qt Scxml:
  171.   ECMAScript data model for QtScxml ...... yes
  172. Qt Gamepad:
  173.   SDL2 ................................... no
  174. Qt 3D:
  175.   Assimp ................................. yes
  176.   System Assimp .......................... no
  177.   Output Qt3D Job traces ................. no
  178.   Output Qt3D GL traces .................. no
  179.   Use SSE2 instructions .................. no
  180.   Use AVX2 instructions .................. no
  181.   Aspects:
  182.     Render aspect ........................ yes
  183.     Input aspect ......................... yes
  184.     Logic aspect ......................... yes
  185.     Animation aspect ..................... yes
  186.     Extras aspect ........................ yes
  187. Qt 3D Renderers:
  188.   OpenGL Renderer ........................ yes
  189. Qt 3D GeometryLoaders:
  190.   Autodesk FBX ........................... no
  191. Qt Wayland Client ........................ no
  192. Qt Wayland Compositor .................... no
  193. Qt Bluetooth:
  194.   BlueZ .................................. no
  195.   BlueZ Low Energy ....................... no
  196.   Linux Crypto API ....................... no
  197.   WinRT Bluetooth API (desktop & UWP) .... no
  198. Qt Sensors:
  199.   sensorfw ............................... no
  200. Qt Quick Controls 2:
  201.   Styles ................................. Default Fusion Imagine Material Universal
  202. Qt Quick Templates 2:
  203.   Hover support .......................... yes
  204.   Multi-touch support .................... yes
  205. Qt Positioning:
  206.   Gypsy GPS Daemon ....................... no
  207.   WinRT Geolocation API .................. no
  208. Qt Location:
  209.   Qt.labs.location experimental QML plugin . yes
  210.   Geoservice plugins:
  211.     OpenStreetMap ........................ yes
  212.     HERE ................................. yes
  213.     Esri ................................. yes
  214.     Mapbox ............................... yes
  215.     MapboxGL ............................. yes
  216.     Itemsoverlay ......................... yes
  217. QtXmlPatterns:
  218.   XML schema support ..................... yes
  219. Qt Multimedia:
  220.   ALSA ................................... no
  221.   GStreamer 1.0 .......................... no
  222.   GStreamer 0.10 ......................... no
  223.   Video for Linux ........................ yes
  224.   OpenAL ................................. no
  225.   PulseAudio ............................. no
  226.   Resource Policy (libresourceqt5) ....... no
  227.   Windows Audio Services ................. no
  228.   DirectShow ............................. no
  229.   Windows Media Foundation ............... no
  230. Qt Tools:
  231.   QDoc ................................... no
  232. Qt WebEngine:
  233.   Embedded build ......................... yes
  234.   Full debug information ................. no
  235.   Pepper Plugins ......................... no
  236.   Printing and PDF ....................... no
  237.   Proprietary Codecs ..................... no
  238.   Spellchecker ........................... yes
  239.   Native Spellchecker .................... no
  240.   WebRTC ................................. no
  241.   Use System Ninja ....................... no
  242.   Geolocation ............................ yes
  243.   WebChannel support ..................... yes
  244.   Use v8 snapshot ........................ yes
  245.   Kerberos Authentication ................ no
  246.   Support qpa-xcb ........................ no
  247.   Building v8 snapshot supported ......... yes
  248.   Use ALSA ............................... no
  249.   Use PulseAudio ......................... no
  250.   Optional system libraries used:
  251.     re2 .................................. no
  252.     icu .................................. no
  253.     libwebp, libwebpmux and libwebpdemux . no
  254.     opus ................................. no
  255.     ffmpeg ............................... no
  256.     libvpx ............................... no
  257.     snappy ............................... no
  258.     glib ................................. no
  259.     zlib ................................. yes
  260.     minizip .............................. no
  261.     libevent ............................. no
  262.     jsoncpp .............................. no
  263.     protobuf ............................. no
  264.     libxml2 and libxslt .................. no
  265.     lcms2 ................................ no
  266.     png .................................. no
  267.     JPEG ................................. no
  268.     harfbuzz ............................. no
  269.     freetype ............................. no
  270.   Required system libraries:
  271.     fontconfig ........................... no
  272.     dbus ................................. no
  273.     nss .................................. no
  274.     khr .................................. yes
  275.     glibc ................................ yes
  276.   Required system libraries for qpa-xcb:
  277.     x11 .................................. yes
  278.     libdrm ............................... no
  279.     xcomposite ........................... no
  280.     xcursor .............................. no
  281.     xi ................................... no
  282.     xtst ................................. no
  283. Note: Also available for Linux: linux-clang linux-icc
  284. Note: PKG_CONFIG_LIBDIR automatically set to /home/anold/firefly-rk3399-ubuntu2004-rootfs/usr/lib/pkgconfig:/home/anold/firefly-rk3399-ubuntu2004-rootfs/usr/share/pkgconfig:/home/anold/firefly-rk3399-ubuntu2004-rootfs/usr/lib/aarch64-linux-gnu/pkgconfig
  285. Note: PKG_CONFIG_SYSROOT_DIR automatically set to /home/anold/firefly-rk3399-ubuntu2004-rootfs
  286. Note: Disabling X11 Accessibility Bridge: D-Bus or AT-SPI is missing.
  287. Note: No wayland-egl support detected. Cross-toolkit compatibility disabled.
  288. WARNING: QDoc will not be compiled, probably because libclang could not be located. This means that you cannot build the Qt documentation.
  289. Either ensure that llvm-config is in your PATH environment variable, or set LLVM_INSTALL_DIR to the location of your llvm installation.
  290. On Linux systems, you may be able to install libclang by installing the libclang-dev or libclang-devel package, depending on your distribution.
  291. On macOS, you can use Homebrew's llvm package.
  292. On Windows, you must set LLVM_INSTALL_DIR to the installation path.
复制代码
OpenGL:
Desktop OpenGL … yes
OpenGL ES 2.0 … no
OpenGL ES 3.0 … no
OpenGL ES 3.1 … no
OpenGL ES 3.2 … no
按照我的方法Desktop OpenGL必然为yes才算成功,你要是需要es2就加es2,你要确定你的rootfs支持es2否则编译不通过。
我这种方法不是完全编译,包罗了大多数我能用到的组件,要想知道QT支持哪些组件,你只需要实行下面的命令挨个看。
  1. cat qtbase/config_help.txt
复制代码
比如OpenGL
  1. -gtk ................. Enable GTK platform theme support [auto]
  2.   -lgmon ............... Enable lgmon support [auto] (QNX only)
  3.   -no-opengl ........... Disable OpenGL support
  4.   -opengl <api> ........ Enable OpenGL support. Supported APIs:
  5.                          es2 (default on Windows), desktop (default on Unix),
  6.                          dynamic (Windows only)
  7.   -opengles3 ........... Enable OpenGL ES 3.x support instead of ES 2.x [auto]
  8.   -egl ................. Enable EGL support [auto]
  9.   -angle ............... Use bundled ANGLE to support OpenGL ES 2.0 [auto]
  10.                          (Windows only)
  11.   -combined-angle-lib .. Merge LibEGL and LibGLESv2 into LibANGLE (Windows only)
  12.   -qpa <name> .......... Select default QPA backend(s) (e.g., xcb, cocoa, windows)
  13.                          A prioritized list separated by semi-colons.
复制代码
至于怎么选就看你自己了,假如报错的话大概率是sysroot的标题,你需要多检查几遍,大概评论我们一起探讨下。
  1. make -j6 && make install
复制代码

总结

1、自己并不难,找到诀窍才是重要的,选不对版本和工具链够头疼的,还是那句话:尽量维持情况同等性。
2、组件很多,编译也不快,最好还是知道哪些组件自己用得到省得反复编译耗时。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

钜形不锈钢水箱

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表