msbuild 链接步骤未运行

msbuild Link step doesn't run

本文关键字:运行 链接 msbuild      更新时间:2023-10-16

我正在尝试使用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)helperinclude;$(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)helperinclude;$(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)helpersrcAppDrv.c" />
    <ClCompile Include="$(ProjectDir)helpersrcBuffers.c" />
    <ClCompile Include="$(ProjectDir)helpersrcSingleThreadAsync.c" />
    <ClCompile Include="$(ProjectDir)helpersrcSlip.c" />
    <ClCompile Include="$(ProjectDir)helpersrcUtils.c" />
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="$(ProjectDir)helperincludeAppDrv.h" />
    <ClInclude Include="$(ProjectDir)helperincludeBuffers.h" />
    <ClInclude Include="$(ProjectDir)helperincludeSingleThreadAsync.h" />
    <ClInclude Include="$(ProjectDir)helperincludeSlip.h" />
    <ClInclude Include="$(ProjectDir)helperincludeUtils.h" />
    <ClInclude Include="$(ProjectDir)helperincludeSharedHeader.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="DebugAppDrv.obj;DebugBuffers.obj;DebugSingleThreadAsync.obj;DebugSlip.obj;DebugUtils.obj" />
  </Target>

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

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

<ConfigurationType>Application</ConfigurationType>

而您正在指定Console这不是MSBuideal识别的东西。