在Windows docker container中编译Qt5项目
Compiling Qt5 project in windows docker container
我正在使用Qt5 5.12.2设置一个Docker容器,并且正在使用Microsoft Visual Studio 15编译器msvc2015_64来构建我的项目。但是,我得到一个LNK1112:构建时模块计算机类型"x64"与目标计算机类型"X86"错误冲突。
我的第一步是使用与Qt Creator生成的相同命令构建Qt5项目:
C:Qt5.12.2msvc2015_64binqmake.exe C:UsersuserADesktopProjectsmyprojapp.pro -spec win32-msvc "CONFIG+=debug" "CONFIG+=qtquickcompiler" && C:QtToolsQtCreatorbinjom.exe qmake_all
C:QtToolsQtCreatorbinjom.exe
这会产生计算机类型冲突错误。
我尝试将以下路径添加到我的 %路径% env 变量中:
C:WindowsSystem32
C:Qt5.12.2msvc2015_64bin
C:Program Files (x86)Microsoft Visual Studio 14.0VCbin
已经在我的路径环境中 env 变量中:
C:Program Files (x86)Windows Kits8.1binx86
C:Program Files (x86)Windows Kits8.1Windows Perormance Toolkit
我还尝试在Visual Studio 14.0 Microsoft运行.bat文件:
C:Program Files (x86)Microsoft Visual Studio 14.0VCbinx86_amd64vcvarsx86_amd64.bat
运行.bat文件的输出:
ERROR: Cannot determine the location of the VS Common Tools folder
我已经查找了此错误,我认为建议将C:WindowsSystem32
添加到 env 变量 %path%。我试过了,但同样的错误。
我的 Dockerfile:
FROM microsoft/windowsservercore:10.0.14393.1884
LABEL Description="Windows Server Core development environment for Qbs with Qt 5.12.2, Chocolatey and various dependencies for testing Qbs modules and functionality"
# Disable crash dialog for release-mode runtimes
RUN reg add "HKLMSOFTWAREMicrosoftWindowsWindows Error Reporting" /v Disabled /t REG_DWORD /d 1 /f
RUN reg add "HKLMSOFTWAREMicrosoftWindowsWindows Error Reporting" /v DontShowUI /t REG_DWORD /d 1 /f
# Install Qt5 5.12.2
COPY qtifwsilent.qs C:\qtifwsilent.qs
RUN powershell -NoProfile -ExecutionPolicy Bypass -Command
$ErrorActionPreference = 'Stop';
$Wc = New-Object System.Net.WebClient ;
$Wc.DownloadFile('http://download.qt.io/archive/qt/5.12/5.12.2/qt-opensource-windows-x86-5.12.2.exe', 'C:qt.exe') ;
Echo 'Downloaded qt-opensource-windows-x86-5.12.2.exe' ;
$Env:QT_INSTALL_DIR = 'C:\Qt' ;
Start-Process C:qt.exe -ArgumentList '--verbose --script C:/qtifwsilent.qs' -NoNewWindow -Wait ;
Remove-Item C:qt.exe -Force ;
Remove-Item C:qtifwsilent.qs -Force
ENV QTDIR C:\Qt\5.12.2\msvc2015
ENV QTDIR64 C:\Qt\5.12.2\msvc2015_64
RUN dir "%QTDIR64%" && dir "%QTDIR64%bin"
# Install choco for psuedo package manager
RUN @powershell -NoProfile -ExecutionPolicy Bypass -Command
$Env:chocolateyVersion = '0.10.8' ;
$Env:chocolateyUseWindowsCompression = 'false' ;
"iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%chocolateybin"
RUN choco install -y python2 --version 2.7.14 && refreshenv && python --version && pip --version
RUN choco install -y qbs --version 1.9.1 && qbs --version
RUN choco install -y unzip --version 6.0 && unzip -v
RUN choco install -y visualcpp-build-tools --version 14.0.25420.1 && dir "%PROGRAMFILES(X86)%Microsoft Visual C++ Build Tools"
# RUN choco install -y windows-sdk-10.1
# RUN choco install -y vcredist2008 --version 9.0.30729.6161
# RUN choco install -y vcredist2010
RUN choco install -y zip --version 3.0 && zip -v
# for building the documentation
RUN pip install beautifulsoup4 lxml
我的 qtifwsilent.qs 用于设置 Qt5 具有以下组件:
widget.deselectAll();
widget.selectComponent("qt.qt5.5122.win32_msvc2015");
widget.selectComponent("qt.qt5.5122.win64_msvc2015_64");
widget.selectComponent("qt.qt5.5122.qtcharts");
widget.selectComponent("qt.qt5.5122.qtdatavis3d");
widget.selectComponent("qt.qt5.5122.qtpurchasing");
widget.selectComponent("qt.qt5.5122.qtvirtualkeyboard");
widget.selectComponent("qt.qt5.5122.qtwebengine");
widget.selectComponent("qt.qt5.5122.qtnetworkauth");
widget.selectComponent("qt.qt5.5122.qtwebglplugin");
widget.selectComponent("qt.qt5.5122.qtscript");
widget.selectComponent("qt.tools.vcredist_msvc2015_x86");
widget.selectComponent("qt.tools.vcredist_msvc2015_x64");
我希望该项目能够构建并生成一个 exe 文件。
我解决了这个问题,所以我只是在这里发布这个以供将来参考。
我不得不更新Dockerfile以使用较新版本的servercore以及所需的Windows工具包。我还必须向我的%path%
环境变量添加几个路径,如下所示。
FROM mcr.microsoft.com/windows/servercore:ltsc2019
LABEL Description="Windows Server Core development environment for Qbs with Qt 5.12.2, Chocolatey and various dependencies for testing Qbs modules and functionality"
# Disable crash dialog for release-mode runtimes
RUN reg add "HKLMSOFTWAREMicrosoftWindowsWindows Error Reporting" /v Disabled /t REG_DWORD /d 1 /f
RUN reg add "HKLMSOFTWAREMicrosoftWindowsWindows Error Reporting" /v DontShowUI /t REG_DWORD /d 1 /f
# Install Qt5 5.12.2
COPY qtifwsilent.qs C:\qtifwsilent.qs
RUN powershell -NoProfile -ExecutionPolicy Bypass -Command
$ErrorActionPreference = 'Stop';
$Wc = New-Object System.Net.WebClient ;
$Wc.DownloadFile('http://download.qt.io/archive/qt/5.12/5.12.2/qt-opensource-windows-x86-5.12.2.exe', 'C:qt.exe') ;
Echo 'Downloaded qt-opensource-windows-x86-5.12.2.exe' ;
$Env:QT_INSTALL_DIR = 'C:\Qt' ;
Start-Process C:qt.exe -ArgumentList '--verbose --script C:/qtifwsilent.qs' -NoNewWindow -Wait ;
Remove-Item C:qt.exe -Force ;
Remove-Item C:qtifwsilent.qs -Force
ENV QTDIR C:\Qt\5.12.2\msvc2015
ENV QTDIR64 C:\Qt\5.12.2\msvc2015_64
RUN dir "%QTDIR64%" && dir "%QTDIR64%bin"
# Install choco for psuedo package manager
RUN @powershell -NoProfile -ExecutionPolicy Bypass -Command
$Env:chocolateyVersion = '0.10.14' ;
$Env:chocolateyUseWindowsCompression = 'false' ;
"iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%chocolateybin"
RUN choco install -y python2 --version 2.7.14 && refreshenv && python --version && pip --version
RUN choco install -y qbs && qbs --version
RUN choco install -y unzip --version 6.0 && unzip -v
RUN choco install -y vcbuildtools -ia "/Full"
RUN choco install -y zip --version 3.0 && zip -v
RUN choco install -y cmake
RUN choco install -y windows-sdk-10.1
RUN choco install -y vcredist2008 --version 9.0.30729.6161
RUN choco install -y vcredist2010
# for building the documentation
RUN pip install beautifulsoup4 lxml
WORKDIR C:\Users\ContainerUser
对于我使用的环境路径:
set path=%path%;"C:Program Files (x86)Microsoft Visual Studio 14.0VC";C:Qt5.12.2msvc2015_64bin;"C:Program Files (x86)Windows Kits10binx64";"C:Program Files (x86)Windows Kits8.1binx64";C:QtToolsQtCreatorbin;
# Run this command to setup cl.exe
vcvarsall.bat x86_amd64
相关文章:
- Qt5:使用QCommandLineParser类时出现奇怪的编译错误
- Qt5 [make -snap] 无法正确编译:进程"/usr/bin/snap"代码 1 退出
- 坚持编译QDoc以在Windows上构建qt5
- 使用 msvc 15 在 Qt5.13 中编译 CUDA 代码
- C++在Linux机器上使用cmake Qt5 Webkit进行交叉编译,使用mingw针对Windows,失败了
- QT5.10.1交叉编译为Raspberry Pi Zero W使用EGLF而不是XCB
- 在Windows docker container中编译Qt5项目
- 在MacOS上使用gcc-8而不是clang编译Qt5
- 在覆盆子上编译Qt5应用程序
- 使用 gcc4.2 在 OsX 10.9 上编译 Qt5.2 项目
- 在Linux for Windows上交叉编译Qt5
- ' /usr/lib/i386-linux-gnu/qt5/bin/lrelease: 未找到 警告:目标为空' 尝试从源代码编译 Feathercoin 时出错
- 使用新的 Qt5 信号/插槽机制连接 QTcpSocket::error() 时编译错误
- Qt5:此代码使用msvc2012编译正常,但使用MinGW编译时出现错误..为什么?
- 链接器找不到qwebp-lib-静态Qt5.3.2编译
- 在OSX 10.10 Yosmite上编译QT5.3时调用函数有歧义
- 如何用Qt5编译QwtPlot3d
- "cannot create .moc/main.moc "有一个错误,当我编译Qt5.7的mysql驱动程序时
- 即使安装了qt5,也强制使用qt4进行编译
- 从QT4转换到QT5导致编译错误;c2666