【发布时间】:2017-01-21 10:49:30
【问题描述】:
最近,我设法使用带有动态版本的 MinGW 5.3.0 构建静态 Qt 5.7.0。因为,我是如何做到这一点的,我已经按照链接中的步骤进行操作:
https://wiki.qt.io/Building_a_static_Qt_for_Windows_using_MinGW
在构建静态 Qt 期间没有出现任何错误(预期(许多)关于已弃用 std::auto_ptr 的警告)。在 Qt Creator 中设置 Qt Version 和 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:\Qt\Static\src\qt-everywhere-opensource-src-5.7.0\qtbase\bin\qmake C:\Qt\
Static\src\qt-everywhere-opensource-src-5.7.0\qtdeclarative\qtdeclarative.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.
MinGW\bin\mingw32-make.exe: *** [Makefile:338: module-qtdeclarative-install_subtargets] Error 3
MinGW\bin\mingw32-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:\Users\Ebisu\Downloads> 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:\Users\Ebisu\Downloads> 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:\Users\Ebisu\Downloads>
现在我的想法已经被打破了。什么?我试图再次在这个新会话中运行脚本,但它在同一个位置停止,并且 AGAIN,python 在它之后无法识别。这怎么可能? python 如何在脚本运行期间变得不可见?
另外请注意,我设法使用了来自这个暂停构建的qmake.exe,它确实编译并将 Qt 代码与 MinGW 6.3.0 链接,预计它不能使用像 QT += multimedia 这样的任何模块(不是正如我预期的那样糟糕,但我仍然想使用模块)。
【问题讨论】:
-
我只能说它在调用python期间每次结果都不同的上下文中非常有趣。你检查过环境变量吗?我相信它是正确的,但只是想交叉检查路径是否被正确提及
-
@RanadipDutta 是的,它设置正确。从 PowerShell python 目录调用
path时,在运行脚本之前、之后和新会话中都存在。 -
@RanadipDutta 好的,在仔细检查 $env:Path 已被脚本覆盖后,不知道我是如何错过的。现在我正在尝试使用修改后的脚本重建 Qt。
-
太棒了。然后这可以简化很多事情:)
标签: python c++ qt powershell mingw