使用MinGW 6.3.0时,Qt 5.7.0的静态构建无法完成

Static building of Qt 5.7.0 fails to complete when using MinGW 6.3.0

本文关键字:构建 静态 MinGW 0时 Qt 使用      更新时间:2023-10-16

最近,我成功地使用动态版本附带的MinGW 5.3.0构建了静态Qt 5.7.0。对于,我是如何做到这一点的,我遵循了链接中的步骤:

https://wiki.qt.io/Building_a_static_Qt_for_Windows_using_MinGW

在构建静态Qt的过程中没有出现任何错误(预期(MANY)关于已弃用的std::auto_ptr的警告)。在Qt Creator中设置了Qt版本和Kit后,它成功地生成了静态链接的可执行文件(甚至不需要CONFIG += static)。

但是,代码似乎只能用静态Qt构建的MinGW版本编译,而动态版本中不存在这种情况,因为我可以用MinGW 5.3.0和MinGW 6.3.0编译并链接Qt代码。尝试将MinGW 6.3.0与静态Qt(使用MinGW 5.3.0构建)一起使用会产生许多未定义的参考错误,如:

error: undefined reference to `QApplication::QApplication(int&, char**, int)'

因此,似乎没有一个Qt库链接到这里(qmake不兼容或其他什么)。

但这并没有让我气馁。我只是再次按照链接中的步骤,但现在用MinGW 6.3.0构建静态Qt(可以设置标志,让脚本知道要使用哪个版本的MinGW)。

这很有希望,脚本构建Qt大约50分钟,然后错误停止了整个过程:

// [...millions of console lines...]
cd qtdeclarative && ( if not exist Makefile C:QtStaticsrcqt-everywhere-opensource-src-5.7.0qtbasebinqmake C:Qt
Staticsrcqt-everywhere-opensource-src-5.7.0qtdeclarativeqtdeclarative.pro -o Makefile ) && D:/Programming_Tools/Nuwe
n/MinGW/bin/mingw32-make.exe -f Makefile install
'python' is not recognized as an internal or external command,
operable program or batch file.
Project ERROR: Building QtQml requires Python.
MinGWbinmingw32-make.exe: *** [Makefile:338: module-qtdeclarative-install_subtargets] Error 3
MinGWbinmingw32-make.exe: Target 'install' not remade because of errors.
Press Enter to continue...:

这里最重要的部分当然是'python' is not recognized as an internal or external command。现在,这是STRANGE,因为我在环境变量PATH中设置了python 3.5.2。

在此之后,我尝试在PowerShell中调用python,结果如下:

PS C:UsersEbisuDownloads> python
python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ python
+ ~~~~~~
+ CategoryInfo          : ObjectNotFound: (python:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

现在,我打开了新的PowerShell会话,并再次调用python。结果如下:

PS C:UsersEbisuDownloads> python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
PS C:UsersEbisuDownloads>

现在我的思绪被震撼了。什么我试图在这个新会话中再次运行该脚本,但它在同一个位置停止了,再次,python在它之后无法识别。这怎么可能?python如何在脚本运行过程中变得不可见?

还要注意的是,我成功地使用了这个暂停的构建中的qmake.exe,它确实编译并链接了Qt代码与MinGW 6.3.0,预计它不能使用任何像QT += multimedia这样的模块(没有我预期的那么糟糕,但我仍然想使用模块)。

刚刚遇到同样的问题。我只想补充一点,在我的情况下,修复包含python的路径没有帮助,因为$env:PYTONPATH仍然指向我的python3安装,然后脚本抛出了一个不同的错误

((File "Lib/site.py", line 176
file=sys.stderr)
^
SyntaxError: invalid syntax).

在powershell脚本中添加其中一行可以修复错误:

$env:PYTHONPATH = "$MingwDiroptbin" 

$env:PYTHONPATH = ""

Qt-configure脚本将先决条件测试结果缓存在文件"config.cache"中。即使您已经将python路径添加到path中,脚本也会一次又一次地写入错误消息。只需将其删除即可强制再次运行此测试。