【问题标题】:Change Platform Toolset when compiling from CMD从 CMD 编译时更改平台工具集
【发布时间】:2021-10-24 09:46:35
【问题描述】:

我想通过 Visual Studio 命令行工具编译一个C++ 程序。我想将可执行文件定位为32 bit Windows XP。尝试使用x86 Native Tools Command Prompt for VS 2019 以通常的方式编译它,但它在Windows XP 上不起作用,但在我的Windows 10 机器上运行良好。

我采取的步骤:

  • 打开x86 Native Tools Command Prompt for VS 2019
  • cd 到项目目录。那里有两个文件夹sourcesheaders,分别包含.cpp.h 文件。
  • 执行命令cl sources\*.cpp /EHsc /D_WIN32_WINNT=0x050103 /I headers /I <path to boost> /link /libpath <path to boost>\boost_1_77_0\bin\x86\lib\libboost_program_options-vc142-mt-s-x32-1_77.lib /out:exec_xp.exe(项目使用boost库)。

试过this,但没用。 /D \"_USING_V110_SDK71_\" 似乎什么都不做,编译器无法识别 /SUBSYSTEM:WINDOWS,5.01 部分。

我从this Microsoft page 了解到,我们应该安装已弃用的工具集来编译WinXP。如教程中所述,我继续访问Visual Studio Installer 并安装了C++ Windows XP Support for VS 2017 (v141) tools [Deprecated]

但是现在呢?如何使用此工具集?我在电脑上的任何地方都找不到它,更不用说使用它了! Visual Studio Installer 说它位于C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools 下,但是太模糊了。

UPD:

尝试使用msbuild /p:PlatformToolset=v141_xp,收到此错误:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(439,
5): error MSB8020: The build tools for v141_xp (Platform Toolset = 'v141_xp') cannot be found. To build using the v141_
xp build tools, please install v141_xp build tools.  Alternatively, you may upgrade to the current Visual Studio tools
by selecting the Project menu or right-click the solution, and then selecting "Retarget solution"

这表明编译器看不到v141_xp 工具集。我想知道为什么?它肯定已经安装了,我是通过 Visual Studio 安装程序完成的。

【问题讨论】:

  • 您是否尝试过在命令行docs.microsoft.com/en-us/visualstudio/msbuild/… 中使用MSBuild
  • @RichardCritten 我没有,但我想我会尝试从 Windows XP 虚拟机编译。谢谢你的提示,如果我这次也失败了,我会求助于你的建议。

标签: c++ windows visual-studio cmd compilation


【解决方案1】:

我建议你可以尝试设置PlatformToolset property:

msbuild myProject.vcxproj /p:PlatformToolset=…

更多详情,建议您参考Doc:MSBuild command-line reference

【讨论】:

  • 现在我有点迷路了,因为我安装了C++ Windows XP Support for VS 2017 (v141) tools [Deprecated],但找不到它。我试图将解决方案重新定位到工具集,但它只是没有显示为菜单中的选项。是不是因为我有 VS 2019 而这个工具集是为 VS 2017 准备的?
  • @winwin 是否要在cmd中使用C++ Windows XP Support for VS 2017 (v141) tools [Deprecated]?如果是这样,您可以尝试使用msbuild myProject.vcxproj /p:PlatformToolset=v141_xp“我已尝试将解决方案重新定位到工具集,但它只是没有显示为菜单中的选项。”这是什么意思?
  • 我已经尝试过从命令行和 IDE 执行您建议的命令,但它表明编译器无法找到构建工具。我已经更新了问题。
  • @winwin 我建议您可以尝试删除 VCTargetsPath 系统变量。
  • 你有任何更新吗?如果您的案例已经解决,请帮忙标记答案。如果没有,请随时与我们联系。您的理解与合作将不胜感激。
猜你喜欢
  • 1970-01-01
  • 2020-07-22
  • 1970-01-01
  • 1970-01-01
  • 2013-03-05
  • 1970-01-01
  • 2013-05-24
  • 1970-01-01
  • 2015-05-25
相关资源
最近更新 更多