从 CMD 编译时更改平台工具集
Change Platform Toolset when compiling from CMD
我想通过 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
到项目目录。我将有 2 个文件夹 sources
和 headers
,它们分别包含 .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
库)。
试过,但没有用。 /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 Studio19\BuildTools
下面,但它太模糊了。
UPD:
尝试使用 msbuild /p:PlatformToolset=v141_xp
,出现此错误:
C:\Program Files (x86)\Microsoft Visual Studio19\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 安装程序安装的。
我建议你可以尝试设置 PlatformToolset property:
msbuild myProject.vcxproj /p:PlatformToolset=…
更多细节,我建议你可以参考文档:MSBuild command-line reference
我想通过 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
到项目目录。我将有 2 个文件夹sources
和headers
,它们分别包含.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
库)。
试过/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 Studio19\BuildTools
下面,但它太模糊了。
UPD:
尝试使用 msbuild /p:PlatformToolset=v141_xp
,出现此错误:
C:\Program Files (x86)\Microsoft Visual Studio19\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 安装程序安装的。
我建议你可以尝试设置 PlatformToolset property:
msbuild myProject.vcxproj /p:PlatformToolset=…
更多细节,我建议你可以参考文档:MSBuild command-line reference