通过命令提示编译c++项目

Compiling c++ project through the command prompt

本文关键字:c++ 项目 编译 提示 命令      更新时间:2023-10-16

我很难弄清楚要在我创建的xml文件中填充什么字段。我一直试图遵循"使用MSBuild创建一个Visual c++项目"(http://msdn.microsoft.com/en-us/library/dd293607.aspx),但我被困在xml部分。所以字段是:

<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>

我知道我必须改变的唯一部分是Item组部分,以匹配我所有的。cpp和。h文件。所有字段都是必需的吗?你能给每个导入项目中的$(VCTargetsPath)一个例子吗?这似乎很简单,但只有在第一次这样做之后。谢谢。

VCTargetsPath是工具集的属性,在注册表中定义。在您的示例中,对于ToolsVersion="12",注册表位置将是HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions12.0。通常,当您安装适当的SDK时,工具集会自动配置。

老实说,我从来没有在编辑器中使用msbuild创建c++项目文件,总是让vs为我做这件事,并通过我单独的自定义构建文件包含/调用vcxproject文件…然而,TargetPath,是为MSBuild的c++配置的目标目录,在我的机器上安装了vs 2013(配置为使用vc++ 12.0工具):C:Program Files (x86)MSBuild Microsoft.Cppv4.0V120.

这些导入定义了ClInclude任务和您的工具支持的所有其他c++相关任务。