安装 MinGW
目前 MinGW 推荐用 WinLibs 家编译的,安装包分为两种运行时:UCRT
和MSVCRT
。
简单地说就是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 | // Decide whether to enable or disable the JIT |
这里没看明白为什么用 MSVC 编译时通过了,用 MinGW 却没有通过。不过根据提示,在编译qtdeclarative
模块时追加force-compile-jit
选项强制开启
1 | qmake.exe -platform win32-g++ CONFIG+=force-compile-jit |
放弃 MinGW
然后尝试用 MinGW 编译的 Qt 运行一个以前的用 VC 的老项目又出现一些新问题,最后懒得折腾了,还是拥抱亲儿子 MSVC 更稳定。
MinGW 的唯一优势可能就是跨平台开发一致的体验,但在稳定性、可调试性、第三方库的支持上都是不如 MSVC 的。