编译 Qt 5.7.1 for arm64 满血版
2025-08-10 15:38:38

准备

硬件:Orange Pi 3B
系统版本

1
2
3
4
5
6
# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal

Qt 版本使用的 5.7.1:https://download.qt.io/new_archive/qt/5.7/5.7.1/submodules/
因为我用的是自己编译的 GCC 15,将 lib 库加入到优先搜索路径中

1
export LD_LIBRARY_PATH=/usr/local/lib64

尽可能多的安装 Qt 依赖的库,这样才能制作满血版的 Qt

1
sudo apt install "^libxcb.*" libx11-dev libx11-xcb-dev libxext-dev libxi-dev libxfixes-dev libglu1-mesa-dev libfreetype6-dev libxrender-dev libfontconfig1-dev libxkbcommon-dev libxkbcommon-x11-dev libdbus-1-dev libasound2-dev libpulse-dev libudev-dev libwayland-dev libatspi2.0-dev libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev zlib1g-dev libssl-dev libpng-dev libjpeg-dev libgbm-dev libdrm-dev libmtdev-dev unixodbc-dev libinput-dev libicu-dev libproxy-dev libdouble-conversion-dev libharfbuzz-dev freetds-dev libcups2-dev libpq-dev

编译

Qt 编译选项如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# ../configure -prefix "/opt/qt-5.7.1" -confirm-license -opensource -opengl es2 -no-sql-mysql -nomake examples -nomake tests

This is the Qt Open Source Edition.

You are licensed to use this software under the terms of
the GNU Lesser General Public License (LGPL) versions 3.
You are also licensed to use this software under the terms of
the GNU General Public License (GPL) versions 2.

You have already accepted the terms of the Open Source license.

Preparing build tree...
Creating qmake...
.Done.
Running configuration tests...
checking for C++14... yes.
checking for C++1z... yes.
checking for default C++ standard edition... yes.
checking for 64-bit std::atomic... yes.
checking for std::atomic for function pointers... yes.
checking for sse2... no.
checking for ipc_sysv... yes.
checking for zlib... yes.
checking for mtdev... yes.
checking for libjpeg... yes.
checking for libpng... yes.
checking for dlopen... no.
checking for libdl... yes.
checking for DB2... no.
checking for InterBase... no.
checking for OCI... no.
checking for ODBC... yes.
checking for PostgreSQL... yes.
checking for SQLite2... no.
checking for TDS... yes.
checking for Cups... yes.
checking for POSIX iconv... yes.
checking for D-Bus... yes.
checking for libproxy... yes.
checking for Glib... yes.
checking for ICU... yes.
checking for PulseAudio... yes.
checking for OpenGL ES 2.0... yes.
checking for OpenGL ES 3.0... yes.
checking for OpenGL ES 3.1... yes.
checking for FontConfig... yes.
checking for libudev... yes.
checking for evdev... yes.
checking for tslib... no.
checking for xkbcommon... yes.
checking for libinput... yes.
checking for XLib... yes.
checking for Xrender... yes.
checking for XInput2... yes.
checking for xcb... yes.
checking for xcb-xkb... yes.
checking for xcb-syslibs... yes.
checking for xcb-render... yes.
checking for xcb-glx... yes.
checking for xcb-xlib... yes.
checking for GBM... yes.
checking for LinuxFB... yes.
checking for KMS... yes.
checking for Mir client... no.
checking for EGL... yes.
checking for EGL-X11... yes.
checking for eglfs-brcm... no.
checking for eglfs-egldevice... yes.
checking for eglfs-mali... yes.
checking for eglfs-viv... no.
checking for DoubleConversion... yes.
checking for HarfBuzz... yes.
checking for STL... yes.
checking for POSIX clock_gettime()... yes.
checking for POSIX Monotonic Clock... yes.
checking for posix_fallocate... yes.
checking for mremap... yes.
checking for getaddrinfo... yes.
checking for inotify... yes.
checking for eventfd... yes.
checking for IPv6 interface name... yes.
checking for getifaddrs... yes.
checking for cloexec... yes.
checking for ppoll... yes.
checking for OpenSSL... yes.
checking for PCRE... yes.
checking for OpenVG... no.
checking for OpenVG... no.
checking for OpenVG (lc includes)... no.
checking for OpenVG (lc includes)... no.
checking for alsa... yes.
checking for GStreamer 1.0... yes.
Done running configuration tests.

Configure summary

Build type: linux-g++ (arm64, CPU features: cx16 neon)
Platform notes:

- Also available for Linux: linux-clang linux-kcc linux-icc linux-cxx

Build options:
Configuration .......... accessibility accessibility-atspi-bridge alsa audio-backend c++11 c++14 c++1z clock-gettime clock-monotonic compile_examples concurrent cups dbus dbus-linked egl eglfs eglfs_egldevice eglfs_gbm eglfs_mali egl_x11 enable_new_dtags evdev eventfd fontconfig full-config gbm getaddrinfo getifaddrs glib gstreamer-1.0 gtk3 iconv icu inotify ipv6ifname kms large-config largefile libinput libproxy libudev linuxfb medium-config minimal-config mremap mtdev neon opengl opengles2 openssl png poll_ppoll posix_fallocate precompile_header pulseaudio qpa qpa reduce_exports release rpath shared small-config system-doubleconversion system-freetype system-harfbuzz system-jpeg system-png system-zlib threadsafe-cloexec use_gold_linker xcb xcb-glx xcb-plugin xcb-render xcb-sm xcb-xlib xinput2 xkbcommon-evdev xlib xrender
Build parts ............ libs tools
Mode ................... release
Using sanitizer(s)...... none
Using C++ standard ..... c++1z
Using gold linker....... yes
Using new DTAGS ........ yes
Using PCH .............. yes
Using LTCG ............. no
Target compiler supports:

Qt modules and options:
Qt D-Bus ............... yes (linked to dbus-1)
Qt Concurrent .......... yes
Qt GUI ................. yes
Qt Widgets ............. yes
Large File ............. yes
QML debugging .......... yes
Use system proxies ..... no

Support enabled for:
Accessibility .......... yes
ALSA ................... yes
CUPS ................... yes
DoubleConversion........ yes (system library)
Evdev .................. yes
FontConfig ............. yes
FreeType ............... yes (system library)
Glib ................... yes
GStreamer .............. yes (1.0)
GTK platformtheme ...... yes
HarfBuzz ............... yes (system library)
Iconv .................. yes
ICU .................... yes
Image formats:
GIF .................. yes (plugin, using bundled copy)
JPEG ................. yes (plugin, using system library)
PNG .................. yes (in QtGui, using system library)
libinput................ yes
Logging backends:
journald ............... no
syslog ............... no
mtdev .................. yes (system library)
Networking:
getaddrinfo .......... yes
getifaddrs ........... yes
IPv6 ifname .......... yes
libproxy.............. yes
OpenSSL .............. yes (loading libraries at run-time)
OpenGL / OpenVG:
EGL .................. yes
OpenGL ............... yes (OpenGL ES 2.0+)
OpenVG ............... no
PCRE ................... system
pkg-config ............. yes
PulseAudio ............. yes
QPA backends:
DirectFB ............. no
EGLFS ................ yes
EGLFS i.MX6 ........ no
EGLFS i.MX6 Wayland. no
EGLFS EGLDevice .... yes
EGLFS GBM .......... yes
EGLFS Mali ......... yes
EGLFS Raspberry Pi . no
EGLFS X11 .......... yes
LinuxFB .............. yes
Mir client............ no
XCB .................. yes (system library)
EGL on X ........... yes
GLX ................ yes
MIT-SHM ............ yes
Xcb-Xlib ........... yes
Xcursor ............ yes (loaded at runtime)
Xfixes ............. yes (loaded at runtime)
Xi2 ................ yes
Xrandr ............. yes (loaded at runtime)
Xrender ............ yes
XKB ................ yes
XShape ............. yes
XSync .............. yes
Session management ..... yes
SQL drivers:
DB2 .................. no
InterBase ............ no
MySQL ................ no
OCI .................. no
ODBC ................. yes (plugin)
PostgreSQL ........... yes (plugin)
SQLite 2 ............. no
SQLite ............... yes (plugin, using bundled copy)
TDS .................. yes (plugin)
tslib .................. no
udev ................... yes
xkbcommon-x11........... yes (system library)
xkbcommon-evdev......... yes
zlib ................... yes (system library)


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.7.1

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

开始吧

1
2
make -j4
make install

第1个错误

1
2
3
4
5
/opt/qtbase-opensource-src-5.7.1/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevice.cpp:74:82: error: invalid conversion from ‘EGLDeviceEXT’ {aka ‘void*’} to ‘EGLNativeDisplayType’ {aka ‘Display*’} [-fpermissive]
74 | return static_cast<QEglFSKmsEglDeviceIntegration *>(m_integration)->eglDevice();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
| |
| EGLDeviceEXT {aka void*}

编辑文件src/plugins/platforms/eglfs/deviceintegration/eglfs_kms_egldevice/qeglfskmsegldevice.cpp

1
2
3
4
5
 EGLNativeDisplayType QEglFSKmsEglDevice::nativeDisplay() const
{
- return static_cast<QEglFSKmsEglDeviceIntegration *>(m_integration)->eglDevice();
+ return reinterpret_cast<EGLNativeDisplayType>(static_cast<QEglFSKmsEglDeviceIntegration *>(m_integration)->eglDevice());
}

解决方案来自 https://code.qt.io/cgit/qt/qtbase.git/commit/?id=f577a01f5e8d9678d268917ca727a6e9a3e819a6

第2个错误

1
2
/opt/qtbase-opensource-src-5.7.1/include/QtCore/../../src/corelib/io/qurl.h:137:9: error: expected identifier before numeric constant
137 | None = 0x0,

代码中的None这个名字与系统头文件(通常是 X11 图形界面的 X.h)中的一个宏定义冲突了。
编辑src/corelib/io/qurl.h文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 先取消 None 宏
#ifdef None
#undef None
#endif

class Q_CORE_EXPORT QUrl
{
public:
enum ParsingMode {
TolerantMode,
StrictMode,
DecodedMode
};

// encoding / toString values
enum UrlFormattingOption {
None = 0x0,
RemoveScheme = 0x1,
RemovePassword = 0x2,
RemoveUserInfo = RemovePassword | 0x4,
RemovePort = 0x8,
RemoveAuthority = RemoveUserInfo | RemovePort | 0x10,
RemovePath = 0x20,
RemoveQuery = 0x40,
RemoveFragment = 0x80,
// 0x100 was a private code in Qt 4, keep unused for a while
PreferLocalFile = 0x200,
StripTrailingSlash = 0x400,
RemoveFilename = 0x800,
NormalizePathSegments = 0x1000
};

善后工作

还原 qurl.h 文件

如果你碰到了前面我碰到的None宏冲突的错误,那么应该在编译好之后移除添加的”补丁”代码,避免污染源文件。
include/QtCore/qurl.h文件还原。

修改 rpath

因为我用的自编译的 GCC,所以最好将其 lib 路径设置为优先搜索

1
2
3
4
5
cd /opt/qt-5.7.1/bin
sudo patchelf --set-rpath '/usr/local/lib64' qmake
sudo patchelf --set-rpath '/usr/local/lib64' moc
sudo patchelf --set-rpath '/usr/local/lib64:$ORIGIN/../lib' uic
sudo patchelf --set-rpath '/usr/local/lib64:$ORIGIN/../lib' qlalr

编译其他模块

qtserialport模块为例

1
2
3
/opt/qt-5.7.1/bin/qmake qtserialport.pro
make -j4
make install

打包

1
tar cJf qt5.7.1-gcc15.1.0-opengl_es2-aarch64-linux-gnu.tar.xz /opt/qt-5.7.1/

这样就可以拷贝到其他机器上使用了。

上一页
2025-08-10 15:38:38