如何在 VS2012 下静态构建 Qt 4.8/5.2,使用静态 MSVC 运行时,支持 Windows XP? [英] How to build Qt 4.8/5.2 statically under VS2012, using the static MSVC runtime, with Windows XP support?

查看:67
本文介绍了如何在 VS2012 下静态构建 Qt 4.8/5.2,使用静态 MSVC 运行时,支持 Windows XP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 VS2012 下制作 Qt 4.8/5.2 的完全静态构建 - 包括静态运行时库,并针对 Windows XP 系统.这不是 Qt 开箱即用的支持,因为即使是 Qt 的静态构建也使用动态链接的 MSVC 运行时.

I'd like to make a completely static build of Qt 4.8/5.2 under VS2012 - including static runtime libraries, and targeting Windows XP systems. This is not supported out-of-the-box by Qt, since even the static build of Qt uses the dynamically linked MSVC runtime.

这是一个规范问题,提供成功构建满足这些要求的 Qt 所需的知识.

This is to be a canonical question that provides the knowledge necessary to successfully build Qt meeting those requirements.

推荐答案

Qt 5.2

假设环境已为 XP 定位准备好,并且相关的 XP 定位 qt5xp.patch 和错误修复 qt5fixes.patch 可用 - 均来自 我的另一个答案,我们必须做到以下几点:

Qt 5.2

Assuming that the environment was prepared for XP targeting, and relevant XP-targeting qt5xp.patch and the bug fix qt5fixes.patch available - both from my other answer, we have to do the following:

  1. 创建一个单独的 win32-msvc2012-staticwin32-msvc2012-static-xp qmake 规范,方法是从 qtbase/mkspecs/win32 复制它们-msvc2012qtbase/mkspecs/win32-msvc2012-xp,分别.

  1. Create a separate win32-msvc2012-static and win32-msvc2012-static-xp qmake specs by copying them from qtbase/mkspecs/win32-msvc2012 and qtbase/mkspecs/win32-msvc2012-xp, respectively.

修改 qmake 规范.

Modify the qmake specs.

教 configure 和 qmake makefile 了解新的 qmake 规范.

Teach configure and qmake makefile about the new qmake specs.

通过在 qtbase 中创建一个空的 .gitignore 文件来强制引导 configure.exe.

Force bootstrap of configure.exe by creating an empty .gitignore file in qtbase.

如果您使用 -prefix 配置 Qt,以便安装和构建目录是分开的,您必须QTBUG-32519 - 至少在该错误得到修复之前.

If you're configuring Qt with a -prefix so that the installation and build directories are separate, you must apply the patch for QTBUG-32519 - at least until that bug gets fixed.

以下批处理文件完成了完整的工作.目前,静态 Qt 构建禁用 webkit 构建.

The following batch file does the complete job. At the moment, webkit building is disabled for static Qt builds.

:: Assume that we're in an equivalent of C:\Qt prefix
@set PREFIX=%~dp0
:: Qt sources
@set QT=%PREFIX%..\5.2.1-src
:: Patch file(s)
@set SRC=%PREFIX%
@set SPEC=win32-msvc2012
@if not exist "%QT%\qt.pro" ( echo Qt source folder expected in %QT%>&2 & exit /b 1 )
::
@patch --forward --directory=%QT% -p0 --global-reject-file=%SRC%\qt5fixes.rej --input=%SRC%\qt5fixes.patch
::
@echo > %QT%\qtbase\.gitignore
@mkdir %QT%\qtbase\mkspecs\%SPEC%-xp
@copy %QT%\qtbase\mkspecs\%SPEC%\qplatformdefs.h %QT%\qtbase\mkspecs\%SPEC%-xp
@copy %QT%\qtbase\mkspecs\%SPEC%\qmake.conf %QT%\qtbase\mkspecs\%SPEC%-xp
@patch --forward --directory=%QT% -p0 --global-reject-file=%SRC%\qt5xp.rej --input=%SRC%\qt5xp.patch
::
@mkdir %QT%\qtbase\mkspecs\%SPEC%-static
@copy %QT%\qtbase\mkspecs\%SPEC%\qplatformdefs.h %QT%\qtbase\mkspecs\%SPEC%-static
@copy %QT%\qtbase\mkspecs\%SPEC%\qmake.conf %QT%\qtbase\mkspecs\%SPEC%-static
@mkdir %QT%\qtbase\mkspecs\%SPEC%-static-xp
@copy %QT%\qtbase\mkspecs\%SPEC%-xp\qplatformdefs.h %QT%\qtbase\mkspecs\%SPEC%-static-xp
@copy %QT%\qtbase\mkspecs\%SPEC%-xp\qmake.conf %QT%\qtbase\mkspecs\%SPEC%-static-xp
@patch --forward --directory=%QT% -p0 --global-reject-file=%SRC%\qt5static.rej --input=%SRC%\qt5static.patch

撤消对 Qt 源的更改,请运行以下命令,变量设置如上:

To undo the changes to the Qt source, run the following, with variables set as above:

@patch --reverse --directory=%QT% -p0 --global-reject-file=%SRC%\qt5static-unfix.rej --input=%SRC%\qt5static.patch
@del %QT%\qtbase\mkspecs\%SPEC%-static\qplatformdefs.h
@del %QT%\qtbase\mkspecs\%SPEC%-static\qmake.conf
@rmdir %QT%\qtbase\mkspecs\%SPEC%-static
@del %QT%\qtbase\mkspecs\%SPEC%-static-xp\qplatformdefs.h
@del %QT%\qtbase\mkspecs\%SPEC%-static-xp\qmake.conf
@rmdir %QT%\qtbase\mkspecs\%SPEC%-static-xp
::
@patch --reverse --directory=%QT% -p0 --global-reject-file=%SRC%\qt5xp-unfix.rej --input=%SRC%\qt5xp.patch
@del %QT%\qtbase\mkspecs\%SPEC%-xp\qplatformdefs.h
@del %QT%\qtbase\mkspecs\%SPEC%-xp\qmake.conf
@rmdir %QT%\qtbase\mkspecs\%SPEC%-xp
@del %QT%\qtbase\.gitignore
::
@patch --reverse --directory=%QT% -p0 --global-reject-file=%SRC%\qt5fixes-unfix.rej --input=%SRC%\qt5fixes.patch

然后通过执行来执行构建

The build is then performed by executing

configure -static -platform win32-msvc2012-static-xp (or win32-msvc2012-static)
jom (or nmake)
jom install (if doing the build separate from the installation directory)

# qt5static.patch
# Static MSVC Runtime Support for Qt 5.2
#
# Build qmake with XP targeting.
--- qtbase/qmake/Makefile.win32 2014-02-20 12:28:23.316380600 -0500
+++ qtbase/qmake/Makefile.win32 2014-02-20 12:29:07.396008900 -0500
@@ -42,7 +42,7 @@
               -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_NO_COMPONENT -DQT_NO_COMPRESS \
               -DQT_NO_THREAD -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT -DQT_NO_DATASTREAM \
               -DUNICODE -DQT_CRYPTOGRAPHICHASH_ONLY_SHA1 -DQT_JSON_READONLY
-!if "$(QMAKESPEC)" == "win32-msvc2012-xp"
+!if "$(QMAKESPEC)" == "win32-msvc2012-xp" || "$(QMAKESPEC)" == "win32-msvc2012-static-xp"
 CFLAGS_BARE = $(CFLAGS_BARE) -D_USING_V110_SDK71_
 !endif
 CFLAGS   = -Yuqmake_pch.h -FIqmake_pch.h -Fpqmake_pch.pch $(CFLAGS_BARE) $(CFLAGS) $(EXTRA_CPPFLAGS)
# Add support for static qmake specs.
--- qtbase/qmake/Makefile.win32 2014-02-01 22:37:30.000000000 -0500
+++ qtbase/qmake/Makefile.win32 2014-02-17 16:21:09.329949100 -0500
@@ -1,4 +1,4 @@
-!IF "$(QMAKESPEC)" == "win32-msvc" || "$(QMAKESPEC)" == "win32-msvc.net" || "$(QMAKESPEC)" == "win32-msvc2002" || "$(QMAKESPEC)" == "win32-msvc2003" || "$(QMAKESPEC)" == "win32-msvc2005" || "$(QMAKESPEC)" == "win32-msvc2008" || "$(QMAKESPEC)" == "win32-msvc2010" || "$(QMAKESPEC)" == "win32-msvc2012" || "$(QMAKESPEC)" == "win32-msvc2012-xp" || "$(QMAKESPEC)" == "win32-msvc2013" || "$(QMAKESPEC)" == "win32-icc"
+!IF "$(QMAKESPEC)" == "win32-msvc" || "$(QMAKESPEC)" == "win32-msvc.net" || "$(QMAKESPEC)" == "win32-msvc2002" || "$(QMAKESPEC)" == "win32-msvc2003" || "$(QMAKESPEC)" == "win32-msvc2005" || "$(QMAKESPEC)" == "win32-msvc2008" || "$(QMAKESPEC)" == "win32-msvc2010" || "$(QMAKESPEC)" == "win32-msvc2012" || "$(QMAKESPEC)" == "win32-msvc2012-static" || "$(QMAKESPEC)" == "win32-msvc2012-static-xp" || "$(QMAKESPEC)" == "win32-msvc2012-xp" || "$(QMAKESPEC)" == "win32-msvc2013" || "$(QMAKESPEC)" == "win32-icc"
 
 !if "$(SOURCE_PATH)" == ""
 SOURCE_PATH = ..

# Set static runtime.
--- qtbase/mkspecs/win32-msvc2012-static/qmake.conf 2014-02-17 23:01:29.965440300 -0500
+++ qtbase/mkspecs/win32-msvc2012-static/qmake.conf 2014-02-17 23:05:51.630568400 -0500
@@ -24,9 +24,9 @@
 QMAKE_CFLAGS            = -nologo -Zm200 -Zc:wchar_t
 QMAKE_CFLAGS_WARN_ON    = -W3
 QMAKE_CFLAGS_WARN_OFF   = -W0
-QMAKE_CFLAGS_RELEASE    = -O2 -MD
-QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi
-QMAKE_CFLAGS_DEBUG      = -Zi -MDd
+QMAKE_CFLAGS_RELEASE    = -O2 -MT
+QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MT -Zi -d2Zi+
+QMAKE_CFLAGS_DEBUG      = -Zi -MTd -d2Zi+
 QMAKE_CFLAGS_YACC       =
 QMAKE_CFLAGS_LTCG       = -GL
 QMAKE_CFLAGS_MP         = -MP
# Set static runtime.
--- qtbase/mkspecs/win32-msvc2012-static-xp/qmake.conf  2014-02-17 23:01:29.965440300 -0500
+++ qtbase/mkspecs/win32-msvc2012-static-xp/qmake.conf  2014-02-17 23:05:51.630568400 -0500
@@ -24,9 +24,9 @@
 QMAKE_CFLAGS            = -nologo -Zm200 -Zc:wchar_t
 QMAKE_CFLAGS_WARN_ON    = -W3
 QMAKE_CFLAGS_WARN_OFF   = -W0
-QMAKE_CFLAGS_RELEASE    = -O2 -MD
-QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi
-QMAKE_CFLAGS_DEBUG      = -Zi -MDd
+QMAKE_CFLAGS_RELEASE    = -O2 -MT
+QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MT -Zi -d2Zi+
+QMAKE_CFLAGS_DEBUG      = -Zi -MTd -d2Zi+
 QMAKE_CFLAGS_YACC       =
 QMAKE_CFLAGS_LTCG       = -GL
 QMAKE_CFLAGS_MP         = -MP

这篇关于如何在 VS2012 下静态构建 Qt 4.8/5.2,使用静态 MSVC 运行时,支持 Windows XP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆