我自己找不到答案。
我尝试使用power shell脚本windows-build-qt-static.ps1
从源代码构建QT。它没有按原样运行,所以我修改了它。我有manualy下载源代码,解压缩它们,放入正确的目录,手动修补mkspecs
# [QT-STATIC-PATCH]
QMAKE_LFLAGS += -static -static-libgcc
QMAKE_CFLAGS_RELEASE -= -O2
QMAKE_CFLAGS_RELEASE += -Os -momit-leaf-frame-pointer
DEFINES += QT_STATIC_BUILD
最后我启动了power shell脚本,它只包含以下部分(我删除的其余代码):
$MingwDir = "c:\Qt\Qt5.7.0\Tools\mingw530_32\"
$QtDir = "c:\Qt\Static\5.7\"
$QtSrcDir = "c:\Qt\Static\src\"
# Set a clean path including MinGW.
$env:Path = "$MingwDir\bin;$MingwDir\opt\bin;$env:SystemRoot\system32;$env:SystemRoot"
# Force English locale to avoid weird effects of tools localization.
$env:LANG = "en"
# Set environment variable QT_INSTALL_PREFIX. Documentation says it should be
# used by configure as prefix but this does not seem to work. So, we will
# also specify -prefix option in configure.
$env:QT_INSTALL_PREFIX = $QtDir
# Configure, compile and install Qt.
Push-Location $QtSrcDir
cmd /c "configure.bat -static -debug-and-release -platform win32-g++ -prefix $QtDir `
-qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -opengl desktop -qt-sql-sqlite -no-openssl `
-make qtserialport -make libs -nomake tools -nomake examples -nomake tests"
mingw32-make -k -j4
mingw32-make -k install
Pop-Location
# Patch Qt's installed mkspecs for static build of application.
$File = "$QtDir\mkspecs\win32-g++\qmake.conf"
@"
CONFIG += static
"@ | Out-File -Append $File -Encoding Ascii
这个编译的库不包含我所需要的(qtserialport,qtcharts,qtconnectivity等)。
然后,我意识到,mingw32-make
配置错误,但我可以在主Makefile
中找到这些行:
...
module-qtserialport-qmake_all: module-qtbase-qmake_all FORCE
@if not exist qtserialport\ mkdir qtserialport\ & if not exist qtserialport\ exit 1
cd qtserialport\ && $(QMAKE) C:\Qt\Static\src\qtserialport\qtserialport.pro -o Makefile
cd qtserialport\ && $(MAKE) -f Makefile qmake_all
module-qtserialport: module-qtbase FORCE
@if not exist qtserialport\ mkdir qtserialport\ & if not exist qtserialport\ exit 1
cd qtserialport\ && ( if not exist Makefile $(QMAKE) C:\Qt\Static\src\qtserialport\qtserialport.pro -o Makefile ) && $(MAKE) -f Makefile
module-qtserialport-make_first: module-qtbase-make_first FORCE
@if not exist qtserialport\ mkdir qtserialport\ & if not exist qtserialport\ exit 1
cd qtserialport\ && ( if not exist Makefile $(QMAKE) C:\Qt\Static\src\qtserialport\qtserialport.pro -o Makefile ) && $(MAKE) -f Makefile
...
我试过发现,为什么很多模块都没有编译。我尝试手动编译它们,但我失败了。
请帮我编译整个Qt Creator(包含所有模块)到静态库中,或者手动将每个模块构建为静态库。
答案 0 :(得分:1)
以后的Qt版本中的构建更加简化,不再需要修补,而是可以使用-static-runtime
。
如果您想构建Qt 5.7.0,步骤如下:
输入configure -static -static-runtime -debug-and-release -prefix /your/directory -no-openssl -nomake tools -nomake examples -nomake tests
(如果需要,可添加其他功能)
mingw32-make -k -j4 (or jom/make)
mingw32-make -k install (or jom/make)
在必须修补某些变量的早期版本中,shell脚本很有用。