VS2017编译32位/64位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配置并编译

  1. 运行VS2017命令行工具,根据要生成的静态库版本选择x86或x64
  2. 切换到QT源代码根目录
  3. 输入configure -confirm-license -opensource -platform win32-msvc -debug-and-release -static -static-runtime -prefix “C:\Qt5.9.7” -no-compile-examples (PS:根据需要修改生成的路径,其它项可根据需要修改)
  4. 根据提示执行jom
  5. 执行jom install

编译过程大概2-3小时。

commanddescription
-platform Select host mkspec[detected]
-confirm-licenseAutomatically acknowledge the license
-opensourceBuild the Open-Source Edition of Qt
-debug-and-releaseBuild two versions of Qt
-staticBuild static Qt libraries
-static-runtimeWith -static,use statuc runtime
-prefixhe deployment directory, as seen on the target device
-no-compile-examplesInstall only the sources of examples
-nomakeExclude part from the list of parts to be built

遇到的问题

编译过的静态库想要更换路径,修改文件夹名称后发现在QTCreator中报错,qmake配置错误。

解决方法:进入修改后的路径下的bin文件夹中,新建qt.conf文件夹,文件夹中添加内容

[Paths]

Prefix = 新的路径

然后回到QTCreator中在选项Qt Versions中删除错误的配置,手动添加新的路径,配置成功后在Kit界面选择相应的Qt版本即可。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值