问题描述
我试图在此处理解可视化的cpp项目文档( https://docs.microsoft.com/zh-cn/cpp/build/walkthrough-using-msbuild-to-create-a-visual-cpp-project ).
I am trying to understand the visual cpp project document here (https://docs.microsoft.com/en-us/cpp/build/walkthrough-using-msbuild-to-create-a-visual-cpp-project).
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.default.props" />
<PropertyGroup>
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="main.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Targets" />
</Project>
我收集到ClCompile是一个项,因为它嵌套在ItemGroup标记下,似乎还可以在ClCompile标记中引用要编译的文件.在项目的文档页面上, https://docs.microsoft.com /en-us/visualstudio/msbuild/msbuild-items ,它指出物料"是构建系统的输入.我没有看到上面的任务需要这些ClCompile项并将其编译,如何实现编译? ClCompile项也是任务吗?
I gather that ClCompile, is an item as it is nested under the ItemGroup tag, it also seems that the files to be compiled are referred to in the ClCompile tag. On the documentation page for Items, https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-items, it states that Items are inputs into the build system. I dont see a task above which takes these ClCompile items and compiles them, how is compilation being achieved? Is the ClCompile item as task as well?
推荐答案
在VCTargets
文件夹中的所有.targets
和.props
文件中搜索以下路径后:
After search all the .targets
and .props
files in the VCTargets
folder under following path:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets
我们可以在Microsoft.CppCommon.targets
文件中找到以下代码段:
We could find following code snippet in the Microsoft.CppCommon.targets
file:
<Target Name="ClCompile"
Condition="'@(ClCompile)' != ''"
DependsOnTargets="SelectClCompile">
<PropertyGroup>
<CLToolArchitecture Condition="'$(CLToolArchitecture)' == ''">$(VCToolArchitecture)</CLToolArchitecture>
<CLDeleteOutputOnExecute Condition="'$(CLDeleteOutputOnExecute)' == ''">true</CLDeleteOutputOnExecute>
</PropertyGroup>
<ItemGroup>
<ClNoDependencies Condition="'@(ClNoDependencies)' == '' and '%(ClInclude.NoDependency)' == 'true'" Include="@(ClInclude)"/>
<ClNoDependencies Condition="'$(NoDependencies)' != ''" Include="$(NoDependencies)" />
</ItemGroup>
...
<OnError Condition="'$(OnXamlPreCompileErrorTarget)' != ''" ExecuteTargets="$(OnXamlPreCompileErrorTarget)" />
</Target>
因此,ClCompile
应该是目标,用于执行Visual C ++编译器工具,而cl.exe
则用于编译C/C ++源文件.这就是为什么不在MSBuild项中的原因.
So ClCompile
should be a target, which is used to execute the Visual C++ compiler tool, cl.exe
to compile the C/C++ source file. That is reason why it not in the MSBuild-item.
有关更多详细信息,请参见 MSBuild(Visual C ++)概述
See MSBuild (Visual C++) Overview for some more details.
这篇关于ClCompile项目也是一项任务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!