首页 > 技术文章 > 安装Qt静态编译环境

strongbug 2021-04-23 08:59 原文

近期在做Qt开发,开发后编译的程序,需要依赖多个Qt库,导致程序目录文件较多。所以在想静态编译的可能。
参考链接:https://blog.csdn.net/gaolijing_/article/details/106822446

准备工作:
1,Qt安装时选中源码(我安装的是Qt 5.14.2);
2,安装Perl、Python
3,在Qt安装目录下Src所在目录中,创建mingw73_32_static

检查:
在应用程序菜单中找到并打开Qt 5.14.2(MinGW 7.3.0 32-bit)
检查:gcc -v 、 perl -v、 python(使用quit()退出)

配置:
切换至Qt源码所在目录,执行下面命令(-prefix后面改为实际路径)
configure.bat  -static -release -confirm-license  -opensource -opengl desktop -platform win32-g++  -prefix "E:\Qt\Qt5.14.2\5.14.2\mingw73_32_static" -sql-sqlite  -sql-odbc -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -make libs  -nomake tools -nomake examples -nomake tests -skip qt3d  -skip qtcanvas3d -skip qtdatavis3d -skip qtlocation -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview

开始编译:
mingw32-make

安装:
mingw32-make install
安装后,刚才建立的mingw73_32_static目录下面就有已经安装的Qt编译环境了。

修改配置文件:
找到新安装的目录下mingw73_32_static\mkspecs\common\g+±win32.conf文件,使用编辑器打开:
1,新增QMAKE_LFLAGS = -static
2,修改QMAKE_LFLAGS_DLL = -static
安装Qt静态编译环境

在QtCreator中配置静态编译器
工具--选项--Kits--Qt Version--添加,
选中新安装的Qt目录下mingw73_32_static\bin\qmake.exe
完成后,点“Apply”。
安装Qt静态编译环境


然后在构建套件中,选中MinGW-32bit,然后点“克隆”,然后修改名称(MinGW-32bit-static)和Qt Version,后点“OK”。
安装Qt静态编译环境


在下次新建工程配置时,选则静态的构建套件即可。


推荐阅读