MinGW 编译 Qt 5.7.1
2025-01-11 12:11:17

安装 MinGW

目前 MinGW 推荐用 WinLibs 家编译的,安装包分为两种运行时:UCRTMSVCRT
简单地说就是MSVCRT用系统自带的msvcrt.dll文件作为运行时,而UCRT是新的链接方式,依赖一堆以api-ms-win*开头的 DLL,所以需要安装 VC 运行库。


如果要支持 XP 系统,直觉上会选择MSVCRT版本,但是其实 XP 上也可以安装新的 VC 运行库,最后一个支持 XP 系统的 VC 运行库版本是14.28.29213
下载地址:VC_redist.x86.exe

编译 Qt

和之前用 MSVC 编译 Qt 差不多,去 https://download.qt.io/new_archive/qt/5.7/5.7.1/submodules 下载对应的模块编译即可。比起 MSVC,用 MinGW 不用修改任何代码,直接编译就能过。
我的编译选项:

1
configure.bat -prefix "C:/Qt/Qt5.7.1-gcc14.2.0-x86" -platform win32-g++ -confirm-license -opensource -release -shared -no-directwrite -no-angle -opengl desktop -nomake examples -nomake tests

-platform要改为win32-g++。仅编译 Release 版本即可,这样可以加快编译进程,除非你要调试 Qt 源码。

QML 问题

我编译了 qtdeclarative 模块,这个模块用于开发 QML 程序,当我运行程序时提示:

1
JIT is disabled for QML. Property bindings and animations will be very slow. Visit https://wiki.qt.io/V4 to learn about possible solutions for your platform.

访问 https://wiki.qt.io/V4 后得知在编译时会自动检测编译器和系统环境,决定是否启用 JIT,在qv4global_p.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Decide whether to enable or disable the JIT

// White list architectures
//
// NOTE: This should match the logic in qv4targetplatform_p.h!

#if defined(Q_PROCESSOR_X86) && !defined(__ILP32__) \
&& (defined(Q_OS_WIN) || defined(Q_OS_LINUX) || defined(Q_OS_QNX) || defined(Q_OS_FREEBSD))
# define V4_ENABLE_JIT
#elif defined(Q_PROCESSOR_X86_64) && !defined(__ILP32__) \
&& (defined(Q_OS_WIN) || defined(Q_OS_LINUX) || defined(Q_OS_MAC) || defined(Q_OS_FREEBSD))
# define V4_ENABLE_JIT
#elif defined(Q_PROCESSOR_ARM_32)
# if defined(thumb2) || defined(__thumb2__) || ((defined(__thumb) || defined(__thumb__)) && __TARGET_ARCH_THUMB-0 == 4)
# define V4_ENABLE_JIT
# elif defined(__ARM_ARCH_ISA_THUMB) && __ARM_ARCH_ISA_THUMB == 2 // clang 3.5 and later will set this if the core supports the Thumb-2 ISA.
# define V4_ENABLE_JIT
# endif
#elif defined(Q_PROCESSOR_ARM_64)
# if defined(Q_OS_LINUX)
# define V4_ENABLE_JIT
# endif
#elif defined(Q_PROCESSOR_MIPS_32) && defined(Q_OS_LINUX)
# define V4_ENABLE_JIT
#endif

// Black list some platforms
#if defined(V4_ENABLE_JIT)
#if defined(Q_OS_IOS) || defined(Q_OS_TVOS)
# undef V4_ENABLE_JIT
#endif
#endif

// For debug purposes: add CONFIG+=force-compile-jit to qmake's command-line to always compile the JIT.
#if defined(V4_FORCE_COMPILE_JIT) && !defined(V4_ENABLE_JIT)
# define V4_ENABLE_JIT
#endif

// Do certain things depending on whether the JIT is enabled or disabled

#ifdef V4_ENABLE_JIT
#define ENABLE_YARR_JIT 1
#define ENABLE_JIT 1
#define ENABLE_ASSEMBLER 1
#else
#define ENABLE_YARR_JIT 0
#define ENABLE_ASSEMBLER 0
#define ENABLE_JIT 0
#endif

这里没看明白为什么用 MSVC 编译时通过了,用 MinGW 却没有通过。不过根据提示,在编译qtdeclarative模块时追加force-compile-jit选项强制开启

1
qmake.exe -platform win32-g++ CONFIG+=force-compile-jit

放弃 MinGW

然后尝试用 MinGW 编译的 Qt 运行一个以前的用 VC 的老项目又出现一些新问题,最后懒得折腾了,还是拥抱亲儿子 MSVC 更稳定。
MinGW 的唯一优势可能就是跨平台开发一致的体验,但在稳定性、可调试性、第三方库的支持上都是不如 MSVC 的。

相关阅读

Qt 用 MSVC 和 MinGW 哪个编译器编译程序比较好?

上一页
2025-01-11 12:11:17
下一页