【发布时间】: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到项目目录。那里有两个文件夹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库)。
试过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