本文主要是介绍交叉编译Qt5.12.8附带编译opengl,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
- 前言
- 一、重要说明
- 二、准备环境
- 1.下载qt5.12.8源代码
- 2.配置系统环境
- 3.安装必要工具
- 4.解压qt5源代码
- 5.开始配置编译
- 6.配置qtcreator
- 三、编译opengl
- 总结
前言
最近有个项目使用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.配置系统环境
sudo apt updatesudo apt install g++-9-aarch64-linux-gnu gcc-9-aarch64-linux-gnu cmake gdb clang
3.安装必要工具
sudo apt install qtbase5-dev qt5-qmake qtcreator
4.解压qt5源代码
tar -xmf qt-everywhere-src-5.12.8.tar.xz
5.开始配置编译
./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构建好之后就可以编译了,注意使用的线程数。
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
软件模拟环境的,这个就不细说了,一般支持定制的板子厂商的维基里都会说明的。
上面的软件照样装,流程照样走一边,只是到了构建的时候命令变了:
./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,根据自己需要编译
等待构建完成…
贴下我的构建输出:
Building on: linux-g++ (x86_64, CPU features: mmx sse sse2)
Building for: linux-aarch64-gnu-g++ (arm64, CPU features: cx16 neon)
Target compiler: gcc 9.4.0
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
Build options:Mode ................................... releaseOptimize release build for size ........ noBuilding shared libraries .............. yesUsing C standard ....................... C11Using C++ standard ..................... C++1zUsing ccache ........................... noUsing gold linker ...................... yesUsing new DTAGS ........................ yesUsing precompiled headers .............. yesUsing LTCG ............................. noTarget compiler supports:NEON ................................. yesBuild parts ............................ libs
Qt modules and options:Qt Concurrent .......................... yesQt D-Bus ............................... yesQt D-Bus directly linked to libdbus .... noQt Gui ................................. yesQt Network ............................. yesQt Sql ................................. yesQt Testlib ............................. yesQt Widgets ............................. yesQt Xml ................................. yes
Support enabled for:Using pkg-config ....................... yesudev ................................... noUsing system zlib ...................... yes
Qt Core:DoubleConversion ....................... yesUsing system DoubleConversion ........ noGLib ................................... noiconv .................................. yesICU .................................... noTracing backend ........................ <none>Logging backends:journald ............................. nosyslog ............................... noslog2 ................................ noUsing system PCRE2 ..................... no
Qt Network:getifaddrs() ........................... yesIPv6 ifname ............................ yeslibproxy ............................... noLinux AF_NETLINK ....................... yesOpenSSL ................................ noQt directly linked to OpenSSL ........ noOpenSSL 1.1 ............................ noDTLS ................................... noSCTP ................................... noUse system proxies ..................... yes
Qt Gui:Accessibility .......................... yesFreeType ............................... yesUsing system FreeType ................ noHarfBuzz ............................... yesUsing system HarfBuzz ................ noFontconfig ............................. noImage formats:GIF .................................. yesICO .................................. yesJPEG ................................. yesUsing system libjpeg ............... noPNG .................................. yesUsing system libpng ................ noEGL .................................... yesOpenVG ................................. noOpenGL:Desktop OpenGL ....................... yesOpenGL ES 2.0 ........................ noOpenGL ES 3.0 ........................ noOpenGL ES 3.1 ........................ noOpenGL ES 3.2 ........................ noVulkan ................................. noSession Management ..................... yes
Features used by QPA backends:evdev .................................. yeslibinput ............................... noINTEGRITY HID .......................... nomtdev .................................. notslib .................................. noxkbcommon .............................. yesX11 specific:XLib ................................. yesXCB Xlib ............................. yesEGL on X11 ........................... yes
QPA backends:DirectFB ............................... noEGLFS .................................. yesEGLFS details:EGLFS OpenWFD ........................ noEGLFS i.Mx6 .......................... noEGLFS i.Mx6 Wayland .................. noEGLFS RCAR ........................... noEGLFS EGLDevice ...................... noEGLFS GBM ............................ noEGLFS VSP2 ........................... noEGLFS Mali ........................... noEGLFS Raspberry Pi ................... noEGLFS X11 ............................ yesLinuxFB ................................ yesVNC .................................... yesMir client ............................. noXCB:Using system-provided XCB libraries .. noXCB XKB .............................. yesXCB XInput ........................... yesNative painting (experimental) ....... noGL integrations:GLX Plugin ......................... yesXCB GLX .......................... noEGL-X11 Plugin ..................... yes
Qt Sql:SQL item models ........................ yes
Qt Widgets:GTK+ ................................... noStyles ................................. Fusion Windows
Qt PrintSupport:CUPS ................................... no
Qt Sql Drivers:DB2 (IBM) .............................. noInterBase .............................. noMySql .................................. noOCI (Oracle) ........................... noODBC ................................... noPostgreSQL ............................. noSQLite2 ................................ noSQLite ................................. yesUsing system provided SQLite ......... noTDS (Sybase) ........................... no
Qt Testlib:Tester for item models ................. yes
Qt SerialBus:Socket CAN ............................. yesSocket CAN FD .......................... yes
Further Image Formats:JasPer ................................. noMNG .................................... noTIFF ................................... yesUsing system libtiff ................. noWEBP ................................... yesUsing system libwebp ................. no
Qt QML:QML network support .................... yesQML debugging and profiling support .... yesQML sequence object .................... yesQML list model ......................... yesQML XML http request ................... yesQML Locale ............................. yesQML delegate model ..................... yes
Qt Quick:Direct3D 12 ............................ noAnimatedImage item ..................... yesCanvas item ............................ yesSupport for Qt Quick Designer .......... yesFlipable item .......................... yesGridView item .......................... yesListView item .......................... yesTableView item ......................... yesPath support ........................... yesPathView item .......................... yesPositioner items ....................... yesRepeater item .......................... yesShaderEffect item ...................... yesSprite item ............................ yes
Qt Scxml:ECMAScript data model for QtScxml ...... yes
Qt Gamepad:SDL2 ................................... no
Qt 3D:Assimp ................................. yesSystem Assimp .......................... noOutput Qt3D Job traces ................. noOutput Qt3D GL traces .................. noUse SSE2 instructions .................. noUse AVX2 instructions .................. noAspects:Render aspect ........................ yesInput aspect ......................... yesLogic aspect ......................... yesAnimation aspect ..................... yesExtras 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 .................................. noBlueZ Low Energy ....................... noLinux Crypto API ....................... noWinRT 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 .......................... yesMulti-touch support .................... yes
Qt Positioning:Gypsy GPS Daemon ....................... noWinRT Geolocation API .................. no
Qt Location:Qt.labs.location experimental QML plugin . yesGeoservice plugins:OpenStreetMap ........................ yesHERE ................................. yesEsri ................................. yesMapbox ............................... yesMapboxGL ............................. yesItemsoverlay ......................... yes
QtXmlPatterns:XML schema support ..................... yes
Qt Multimedia:ALSA ................................... noGStreamer 1.0 .......................... noGStreamer 0.10 ......................... noVideo for Linux ........................ yesOpenAL ................................. noPulseAudio ............................. noResource Policy (libresourceqt5) ....... noWindows Audio Services ................. noDirectShow ............................. noWindows Media Foundation ............... no
Qt Tools:QDoc ................................... no
Qt WebEngine:Embedded build ......................... yesFull debug information ................. noPepper Plugins ......................... noPrinting and PDF ....................... noProprietary Codecs ..................... noSpellchecker ........................... yesNative Spellchecker .................... noWebRTC ................................. noUse System Ninja ....................... noGeolocation ............................ yesWebChannel support ..................... yesUse v8 snapshot ........................ yesKerberos Authentication ................ noSupport qpa-xcb ........................ noBuilding v8 snapshot supported ......... yesUse ALSA ............................... noUse PulseAudio ......................... noOptional system libraries used:re2 .................................. noicu .................................. nolibwebp, libwebpmux and libwebpdemux . noopus ................................. noffmpeg ............................... nolibvpx ............................... nosnappy ............................... noglib ................................. nozlib ................................. yesminizip .............................. nolibevent ............................. nojsoncpp .............................. noprotobuf ............................. nolibxml2 and libxslt .................. nolcms2 ................................ nopng .................................. noJPEG ................................. noharfbuzz ............................. nofreetype ............................. noRequired system libraries:fontconfig ........................... nodbus ................................. nonss .................................. nokhr .................................. yesglibc ................................ yesRequired system libraries for qpa-xcb:x11 .................................. yeslibdrm ............................... noxcomposite ........................... noxcursor .............................. noxi ................................... noxtst ................................. noNote: Also available for Linux: linux-clang linux-iccNote: 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/pkgconfigNote: PKG_CONFIG_SYSROOT_DIR automatically set to /home/anold/firefly-rk3399-ubuntu2004-rootfsNote: Disabling X11 Accessibility Bridge: D-Bus or AT-SPI is missing.Note: No wayland-egl support detected. Cross-toolkit compatibility disabled.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.
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支持哪些组件,你只需要执行下面的命令挨个看。
cat qtbase/config_help.txt
比如OpenGL
-gtk ................. Enable GTK platform theme support [auto]-lgmon ............... Enable lgmon support [auto] (QNX only)-no-opengl ........... Disable OpenGL support-opengl <api> ........ Enable OpenGL support. Supported APIs:es2 (default on Windows), desktop (default on Unix),dynamic (Windows only)-opengles3 ........... Enable OpenGL ES 3.x support instead of ES 2.x [auto]-egl ................. Enable EGL support [auto]-angle ............... Use bundled ANGLE to support OpenGL ES 2.0 [auto](Windows only)-combined-angle-lib .. Merge LibEGL and LibGLESv2 into LibANGLE (Windows only)-qpa <name> .......... Select default QPA backend(s) (e.g., xcb, cocoa, windows)A prioritized list separated by semi-colons.
至于怎么选就看你自己了,如果报错的话大概率是sysroot
的问题,你需要多检查几遍,或者评论我们一起探讨下。
make -j6 && make install
总结
1、本身并不难,找到诀窍才是重要的,选不对版本和工具链够头疼的,还是那句话:尽量维持环境一致性。
2、组件很多,编译也不快,最好还是知道哪些组件自己用得到免得反复编译耗时。
这篇关于交叉编译Qt5.12.8附带编译opengl的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!