相关链接
演练:使用 MSBuild 创建 Visual C++ 项目
1. 设置编译选项
要编译时向cl.exe
添加编译选项, 需要使用环境变量 CL
传递, 包括增加宏定义
set CL=/utf-8;/D_CRT_SECURE_NO_WARNINGS;/D_USING_V120_SDK71_;%CL%
<ClCompile>
<AdditionalOptions>/Gw %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
2. 添加链接参数
参考链接 https://learn.microsoft.com/en-us/cpp/build/reference/linking?view=msvc-170
向link.exe
传递参数需要设置 LINK
或_LINK_
环境变量
LINK environment variables
The linker recognizes the following environment variables:
LINK and LINK, if defined. The linker prepends the options and arguments defined in the LINK environment variable and appends the options and arguments defined in the LINK environment variable to the command line arguments before processing.
LIB, if defined. The linker uses the LIB path when it searches for an object, library, or other file specified on the command line or by the /BASE option. It also uses the LIB path to find a .pdb file named in an object. The LIB variable can contain one or more path specifications, separated by semicolons. One path must point to the \lib subdirectory of your Visual C++ installation.
PATH, if the tool needs to run CVTRES and can’t find the file in the same directory as link.exe itself. (link.exe requires CVTRES to link a .res file.) PATH must point to the \bin subdirectory of your Visual C++ installation.
TMP, to specify a directory when linking OMF or .res files.
3. 设置工具集
# 使用xp的工具集 -m表示并行编译
msbuild.exe -p:PlatformToolset=v140_xp -m`-t:rebuild "target.sln"