Qbs 设置目标机器类型

Qbs setting target machine type

我正在尝试在 Windows 10 x64 上构建 Qbs 示例 collidingmice 并收到以下错误消息:

Qt5Cored.lib(Qt5Cored.dll) : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86'

我尝试在 collidingmice.qbs

中设置以下内容
qbs.architecture : "x64"

收到消息

'x64' differs from the architecture produced by this compiler (x86)

然后我尝试了

qbs.architecture : "x86_64"

给出了错误信息;

'x86_64' differs from the architecture produced by this compiler (x86)

然后我尝试了

qbs.architecture : "x86"

给出了错误信息;

Qt5Cored.lib(Qt5Cored.dll) : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86'

有没有办法设置目标机器类型,例如到 Qbs 中的 'x86''x64'?

我的猜测是您使用的是 x86 编译器和 x64 Qt,这将不起作用。您是如何设置个人资料的?

以下是我在使用 Qbs 构建系统("Tiled",游戏地图编辑器)构建应用程序时如何解决同样的问题。就我而言,我使用的是 Visual Studio 2019 x64 工具链。

注意:此答案假定 Qt 和 Qbs 在您的路径中。

  1. 打开命令提示符
  2. 运行 "C:\Program Files (x86)\Microsoft Visual Studio19\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 在命令提示符中初始化 VS2019 环境变量。
  3. cd 到您的 .qbs 项目所在的目录。
cd myproject
  1. 为您的构建创建一个新的影子构建目录并 cd 进入它。
mkdir build-myproject
cd build-myproject
  1. 运行 qbs setup-toolchains --detect 应该可以找到您的 VS2019 环境。
  2. 运行 qbs setup-qt --detect 应该可以找到您的 Qt 环境(假设您已添加到 PATH)。
  3. 运行 qbs config --list profiles 显示检测到的工具链配置文件。

示例:

qbs config --list profiles
profiles.MSVC2019-x64.cpp.compilerVersion: "19.25.28614"
profiles.MSVC2019-x64.cpp.toolchainInstallPath: "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64"
profiles.MSVC2019-x64.qbs.architecture: "x86_64"
profiles.MSVC2019-x64.qbs.targetPlatform: "windows"
profiles.MSVC2019-x64.qbs.toolchainType: "msvc"
...
  1. MSVC2019 x64 配置文件名为 "MSVC2019-x64"。现在在构建应用程序时通过 qbs 属性 指定:
qbs build -f ..\MyAwesomeProject.qbs profile:MSVC2019-x64

可以以类似的方式构建 x86,只要 Qt 的 x86 构建可用。 运行将 vcvarsall.bat 批处理文件与 x86 结合使用将设置您的命令提示符以使用 VS x86 环境变量。