安装MinGW工具链环境
这里在Win32环境下要安装一个
MinGW
工具链,这里最好是先安装一个Qt环境,使用Qt自带的MinGW工具链,我这里是先安装一个Qt5.6的环境再用它来编译Qt5.3.2的静态库.下载并安装ActivePerl
软件.-
这里要用到MSYS环境,把编译
ICU
,openssl
的gcc 都指向QT5.6.1自带的工具链GCC,这样才能保能Qt,ICU,openssl
编译出来的C++二进制文是兼容的,修改msys_env.bat
脚本如下:1234set path=C:\Python27;C:\Perl\bin;C:\Qt\Qt5.6.1\Tools\mingw492_32\bin;D:\mingw\bin;D:\mingw\mingw32\bin;D:\mingw\msys\1.0\binset HOME=D:\mingw\msys\1.0bash.exe 修改
fstab
文件,这里从*
看到解释
1
2
|
C:/Qt/Qt5.6.1/Tools/mingw492_32 /mingw
c:/perl/Perl
|
下载ICU
- 经过测试通过下面页下载的库是不能用来静态链接的.还是需要自已用QT的
mingw-GCC
工具链编译源码才能用. - 根据链接Qt5.3 Tools and Versions 下载一个合适的ICU
- 打开http://download.qt.io/development_releases/prebuilt/icu/prebuilt/mingw/ 选择下载
icu_53_1_mingw_builds_4_9_1_posix_seh_64_devel.7z
下载编译ICU
- 下载ICU4C_53_1
- 这里以icu-53_1为例编译 解压ICU包进入到source目录
1
2
3
4
5
|
bash.exe-3.1$ cd icu/source
bash.exe-3.1$ ./runConfigureICU MinGW --prefix=/c/icu4c53_1 --enable-static --disable-shared
--enable-release --disable-debug
[...]
bash.exe-3.1$ make && make install
|
编译openssl
- 下载 https://www.openssl.org/source/openssl-1.0.1g.tar.gz
- 编译openssl 必需要有msys环境.请仔细查看解压后文件夹里的
INSTALL.W32
文档. - 运行
msys shell
,切换的openssl-1.0.1g
目录下:1234567bash.exe-3.1$ ./config --prefix=/c/openssl-1.0.1g no-asm no-shared[...]bash.exe-3.1$ make depend[...]bash.exe-3.1$ make[...]bash.exe-3.1$ make install
编译Qt源码
- 下载Qt5.3.2
- 解压文件并且修改
qtbase\mkspecs\win32-g++\qmake.conf
最终文件如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# qmake configuration for win32-g++
#
# Written for MinGW / gcc 4.6 or higher
#
# Cross compile example for i686-w64-mingw32-g++:
# configure -xplatform win32-g++ -device-option CROSS_COMPILE=i686-w64-mingw32-
#
load(device_config)
MAKEFILE_GENERATOR = MINGW
QMAKE_PLATFORM = win32 mingw
CONFIG += debug_and_release debug_and_release_target precompile_header
DEFINES += UNICODE
QMAKE_COMPILER_DEFINES += __GNUC__ WIN32
QMAKE_EXT_OBJ = .o
QMAKE_EXT_RES = _res.o
QMAKE_COMPILER = gcc
QMAKE_CC = $${CROSS_COMPILE}gcc
QMAKE_LEX = flex
QMAKE_LEXFLAGS =
QMAKE_YACC = byacc
QMAKE_YACCFLAGS = -d
QMAKE_CFLAGS = -pipe -fno-keep-inline-dllexport
QMAKE_CFLAGS_DEPS = -M
QMAKE_CFLAGS_WARN_ON = -Wall -Wextra
QMAKE_CFLAGS_WARN_OFF = -w
QMAKE_CFLAGS_RELEASE -= -O2
QMAKE_CFLAGS_RELEASE += -Os -momit-leaf-frame-pointer #注意这一行
QMAKE_CFLAGS_DEBUG = -g
QMAKE_CFLAGS_YACC = -Wno-unused -Wno-parentheses
QMAKE_CFLAGS_SPLIT_SECTIONS = -ffunction-sections
QMAKE_CFLAGS_SSE2 = -msse2 -mstackrealign
QMAKE_CFLAGS_SSE3 = -msse3
QMAKE_CFLAGS_SSSE3 = -mssse3
QMAKE_CFLAGS_SSE4_1 = -msse4.1
QMAKE_CFLAGS_SSE4_2 = -msse4.2
QMAKE_CFLAGS_AVX = -mavx
QMAKE_CFLAGS_AVX2 = -mavx2
QMAKE_CFLAGS_IWMMXT = -mcpu=iwmmxt
QMAKE_CFLAGS_NEON = -mfpu=neon
QMAKE_CXX = $${CROSS_COMPILE}g++
QMAKE_CXXFLAGS = $$QMAKE_CFLAGS
QMAKE_CXXFLAGS_DEPS = $$QMAKE_CFLAGS_DEPS
QMAKE_CXXFLAGS_WARN_ON = $$QMAKE_CFLAGS_WARN_ON
QMAKE_CXXFLAGS_WARN_OFF = $$QMAKE_CFLAGS_WARN_OFF
QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE
QMAKE_CXXFLAGS_DEBUG = $$QMAKE_CFLAGS_DEBUG
QMAKE_CXXFLAGS_YACC = $$QMAKE_CFLAGS_YACC
QMAKE_CXXFLAGS_THREAD = $$QMAKE_CFLAGS_THREAD
QMAKE_CXXFLAGS_RTTI_ON = -frtti
QMAKE_CXXFLAGS_RTTI_OFF = -fno-rtti
QMAKE_CXXFLAGS_EXCEPTIONS_ON = -fexceptions -mthreads
QMAKE_CXXFLAGS_EXCEPTIONS_OFF = -fno-exceptions
QMAKE_CXXFLAGS_CXX11 = -std=c++0x
QMAKE_CXXFLAGS_SPLIT_SECTIONS = $$QMAKE_CFLAGS_SPLIT_SECTIONS
QMAKE_INCDIR =
QMAKE_RUN_CC = $(CC) -c $(CFLAGS) $(INCPATH) -o $obj $src
QMAKE_RUN_CC_IMP = $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
QMAKE_RUN_CXX = $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $obj $src
QMAKE_RUN_CXX_IMP = $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
QMAKE_LINK = $${CROSS_COMPILE}g++
QMAKE_LINK_C = $${CROSS_COMPILE}gcc
QMAKE_LFLAGS = -static -static-libgcc # 添加这一行
QMAKE_LFLAGS_EXCEPTIONS_ON = -mthreads
QMAKE_LFLAGS_EXCEPTIONS_OFF =
QMAKE_LFLAGS_RELEASE = -Wl,-s
QMAKE_LFLAGS_DEBUG =
QMAKE_LFLAGS_CONSOLE = -Wl,-subsystem,console
QMAKE_LFLAGS_WINDOWS = -Wl,-subsystem,windows
QMAKE_LFLAGS_DLL = -static
QMAKE_LFLAGS_CXX11 =
QMAKE_LFLAGS_GCSECTIONS = -Wl,--gc-sections
QMAKE_LINK_OBJECT_MAX = 10
QMAKE_LINK_OBJECT_SCRIPT = object_script
QMAKE_PREFIX_STATICLIB = lib
QMAKE_EXTENSION_STATICLIB = a
QMAKE_LIBS =
QMAKE_LIBS_CORE = -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32
QMAKE_LIBS_GUI = -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lws2_32 -lole32 -luuid -luser32 -ladvapi32
QMAKE_LIBS_NETWORK = -lws2_32
QMAKE_LIBS_OPENGL = -lglu32 -lopengl32 -lgdi32 -luser32
QMAKE_LIBS_OPENGL_ES2 = -llibEGL -llibGLESv2 -lgdi32 -luser32
QMAKE_LIBS_OPENGL_ES2_DEBUG = -llibEGLd -llibGLESv2d -lgdi32 -luser32
QMAKE_LIBS_COMPAT = -ladvapi32 -lshell32 -lcomdlg32 -luser32 -lgdi32 -lws2_32
QMAKE_LIBS_QT_ENTRY = -lmingw32 -lqtmain
!isEmpty(QMAKE_SH) {
MINGW_IN_SHELL = 1
QMAKE_DIR_SEP = /
QMAKE_DIRLIST_SEP = :
include(../common/shell-unix.conf)
# Because install's ability to set permissions is not relevant on Windows,
# and git's msys does not provide it to start with.
QMAKE_INSTALL_FILE = cp -f
QMAKE_INSTALL_PROGRAM = cp -f
} else {
include(../common/shell-win32.conf)
}
QMAKE_IDL = midl
QMAKE_LIB = $${CROSS_COMPILE}ar -ru
QMAKE_RC = $${CROSS_COMPILE}windres
QMAKE_STRIP = $${CROSS_COMPILE}strip
QMAKE_STRIPFLAGS_LIB += --strip-unneeded
QMAKE_OBJCOPY = $${CROSS_COMPILE}objcopy
QMAKE_NM = $${CROSS_COMPILE}nm -P
load(qt_config)
|
创建编译脚本
- 创建一个bat的脚本件内容如下,有些变量请按实际系统环境做相应的修改.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
set RDIR=c:/Qt/Qt5.6.1
set VERGCC=mingw492_32
set PATH=C:/Python27;C:/Perl/bin;%RDIR%/5.6/%VERGCC%/bin;%RDIR%/Tools/%VERGCC%/bin;C:\icu\bin;%RDIR%/Tools/QtCreator/bin
set INCLUDE=%RDIR%/5.6/%VERGCC%/include;%RDIR%/Tools/%VERGCC%/include;C:\icu4c53_1\include;C:\openssl-1.0.1g\include
set LIB=%RDIR%/5.6/%VERGCC%/lib;%RDIR%/Tools/%VERGCC%/lib;C:\icu4c53_1\lib;C:\openssl-1.0.1g\lib
set SDIR=D:/qt-everywhere-opensource-src-5.3.2
cd %SDIR%
configure.bat -mp -platform win32-g++ -opensource -confirm-license -release
-static -ltcg -c++11 -prefix "c:/Qt/5.3.2-static" -accessibility
-rtti -qt-sql-sqlite -qt-sql-odbc -plugin-sql-sqlite -plugin-sql-odbc -icu -qt-zlib -qt-libpng -qt-libjpeg
-audio-backend -opengl desktop -qml-debug -no-vcproj -no-dbus -nomake tests
-openssl -I C:/openssl-1.0.1g/include -L C:/openssl-1.0.1g/lib
-nomake examples -qt-freetype -no-compile-examples -no-openvg -iconv -no-directwrite
-no-iwmmxt -no-crt -skip qtwebkit
;编译
mingw32-make
;安装到-prefix的变量路径中
mingw32-make install
|
https://yjdwbj.github.io/2016/06/27/%E5%9C%A8Windows-%E7%8E%AF%E5%A2%83%E4%B8%8B%E7%BC%96%E8%AF%91Qt%E9%9D%99%E6%80%81%E5%BA%93/