VS2017 QT静态库版本编译
windows下QT静态库编译
记录windows下使用vs2017编译qt5.9.7版本32位,64位静态库过程
准备工具
- QT源码压缩包 这里使用的5.9.7版本的zip包
- Visual Studio2017开发环境
- Python
- Perl
- Ruby
编译过程
第一步 解压源代码修改文件
解压好源代码之后进入“ \qtbase\mkspecs\common”路径下,打开msvc-desktop.conf文件进行修改。
QMAKE_CFLAGS_RELEASE = $$QMAKE_CFLAGS_OPTIMIZE -MD
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += $$QMAKE_CFLAGS_OPTIMIZE -Zi -MD
QMAKE_CFLAGS_DEBUG = -Zi -MDd
将文件中38行左右位置的三处-MD修改为 -MT
第二步 完成configure配置并编译
- 运行VS2017命令行工具,根据要生成的静态库版本选择x86或x64
- 切换到QT源代码根目录
- 输入configure -confirm-license -opensource -platform win32-msvc -debug-and-release -static -static-runtime -prefix “C:\Qt5.9.7” -no-compile-examples (PS:根据需要修改生成的路径,其它项可根据需要修改)
- 根据提示执行jom
- 执行jom install
编译过程大概2-3小时。
command | description |
---|---|
-platform | Select host mkspec[detected] |
-confirm-license | Automatically acknowledge the license |
-opensource | Build the Open-Source Edition of Qt |
-debug-and-release | Build two versions of Qt |
-static | Build static Qt libraries |
-static-runtime | With -static,use statuc runtime |
-prefix | he deployment directory, as seen on the target device |
-no-compile-examples | Install only the sources of examples |
-nomake | Exclude part from the list of parts to be built |
… | … |
遇到的问题
编译过的静态库想要更换路径,修改文件夹名称后发现在QTCreator中报错,qmake配置错误。
解决方法:进入修改后的路径下的bin文件夹中,新建qt.conf文件夹,文件夹中添加内容
[Paths]
Prefix = 新的路径
然后回到QTCreator中在选项Qt Versions中删除错误的配置,手动添加新的路径,配置成功后在Kit界面选择相应的Qt版本即可。