msbuild链接步骤不运行

时间:2016-03-09 15:26:34

标签: c++ msbuild

我正在尝试使用MSBuild构建一个非常简单的C程序。以前这是由一个使用Visual Studio的实习生组成的,但我们不会在这里使用VS而且我希望这个用MSBuild构建,所以我可以自动化它。

我已经在MSDN和其他参考文档的演练之后从头构建了我的vcxproj文件。我能够编译obj文件没问题,但链接步骤似乎永远不会运行所以我没有得到可执行输出。

在AppDrv.c文件中有一个名为main的函数,可以安全地假设链接器将检测到它作为入口点,或者我是否需要手动告诉msbuild一些它是如何存在的?

这是我的vcxproj的全部内容。我在文档中找不到任何说明我需要告诉它链接的内容,如果CL步骤完成,它是不是会自动发生?我是否需要以某种方式明确列出要链接的obj文件,或者MSBuild可以自己解决这个问题吗?

<Project DefaultTargets="Build" ToolsVersion="14.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>Console</ConfigurationType>
    <PlatformToolset>v140</PlatformToolset>
  </PropertyGroup>


  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <!--Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /-->


  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>false</LinkIncremental>
    <IncludePath>$(UniversalCRT_IncludePath)$(ProjectDir)helper\include;$(WindowsSDK_IncludePath)$(VC_IncludePath)</IncludePath>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <CompileAs>CompileAsC</CompileAs>
      <WarningLevel>TurnOffAllWarnings</WarningLevel>
      <Optimization>Disabled</Optimization>
      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <OutputFile>slip_windows_helper.exe</OutputFile>
      <ShowProgress>LinkVerbose</ShowProgress>
    </Link>
  </ItemDefinitionGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
    <IncludePath>$(UniversalCRT_IncludePath)$(ProjectDir)helper\include;$(WindowsSDK_IncludePath)$(VC_IncludePath)</IncludePath>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <CompileAs>CompileAsC</CompileAs>
      <WarningLevel>TurnOffAllWarnings</WarningLevel>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
    </Link>
  </ItemDefinitionGroup>


  <ItemGroup>
    <ClCompile Include="$(ProjectDir)helper\src\AppDrv.c" />
    <ClCompile Include="$(ProjectDir)helper\src\Buffers.c" />
    <ClCompile Include="$(ProjectDir)helper\src\SingleThreadAsync.c" />
    <ClCompile Include="$(ProjectDir)helper\src\Slip.c" />
    <ClCompile Include="$(ProjectDir)helper\src\Utils.c" />
  </ItemGroup>

  <ItemGroup>
    <ClInclude Include="$(ProjectDir)helper\include\AppDrv.h" />
    <ClInclude Include="$(ProjectDir)helper\include\Buffers.h" />
    <ClInclude Include="$(ProjectDir)helper\include\SingleThreadAsync.h" />
    <ClInclude Include="$(ProjectDir)helper\include\Slip.h" />
    <ClInclude Include="$(ProjectDir)helper\include\Utils.h" />
    <ClInclude Include="$(ProjectDir)helper\include\SharedHeader.h" />
  </ItemGroup>


  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Targets" />


    <Target Name="Info">
        <Message Text="Target to output MSBuild information" />
        <Message Text="OutputAssembly: $(OutputAssembly)" />
        <Message Text="VCTargetsPath: $(VCTargetsPath)" />
        <Message Text="Includes: $(IncludePath)" />
        <Message Text="VC_IncludePath:$(VC_IncludePath)" />
        <Message Text="WindowsSDK_IncludePath:$(WindowsSDK_IncludePath)" />
        <Message Text="the property config is: $(Configuration)" />
        <Message Text="final output directory: $(OutDir)" />
    </Target>


</Project>

这是我用来启动构建的命令:

MSBuild.exe slipwinhelper.vcxproj /p:configuration=Debug /p:platform=Win32 /p:OutDir=target\ /nologo /t:Clean;Build;Info

更新: 我通过覆盖AfterBuild事件来运行链接任务:

  <Target Name="AfterBuild">
      <Link Sources="Debug\AppDrv.obj;Debug\Buffers.obj;Debug\SingleThreadAsync.obj;Debug\Slip.obj;Debug\Utils.obj" />
  </Target>

但是现在它在代码中给了我未解决的SetupApi调用外部。我尝试将SubSystem更改为Windows,但这似乎不起作用。

1 个答案:

答案 0 :(得分:1)

与VS生成的文件快速比较显示了一堆差异/缺乏属性,包括来自VS的文件

<ConfigurationType>Application</ConfigurationType>

而你指的是Console这不是msbuild认可的东西。