简体   繁体   中英

C++ project gets rebuilt due to missing lnk{...}.tmp file in Visual Studio 2022

I have a project in my solution which gets built (consequently all the dependent projects as well) on every run due to the following file missing. I changed the build output verbosity to Diagnostics and got the following line at the top of the build of the said project:

Build started...

1>------ Up-To-Date check: Project: project_name.vcxproj, Configuration: Release x64 ------

1>Project is not up-to-date: build output 'c:\path\appdata\local\temp\lnk{24e28c62-71a7-43ad-81e2-9b34157645b4}.tmp' is missing

1>------ Build started: Project: project_name, Configuration: Release x64 ------

This number (24e28c62-71a7-43ad-81e2-9b34157645b4) changes on every build.

The solutions that I have tried which didn't work:

The rebuild happens when I click the build solution regardless of any changes or lack there of in the code.

Edit:

The linker /VERBOSE output on building the said project:

Build started...
1>------ Build started: Project: project_name, Configuration: Release x64 ------
1>Invoking cvtres.exe:
1> /machine:amd64
1> /verbose
1> /out:"C:\Users\path\AppData\Local\Temp\lnk{01385313-5798-4F09-8223-983424FE6954}.tmp"
1> /readonly
1> "C:\Dev\dev\ws2\build\Release_x64\i\project_name\name-of-dll.res"
1>Microsoft (R) Windows Resource To Object Converter Version 14.30.30711.1
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>
1>adding resource. type:VERSION, name:1, language:0x0407, flags:0x30, size:576

You seem to be building a DLL. So this doesn't apply to you. But for others that get this when building a static library , hang on...

Here's a possible cause for rebuilds:

  • Your static library project might contain a resource ( *.RC ) file.

It's quite odd for a static library to contain a RC file because it could clash with other projects in your solution that consume the static library.

Deleting the .rc and resource.h files can solve the issue (at least it did for me).

The other (top) reason is that your project file points to header files that you have deleted. Since the compiler is not invoked for header files, you won't see errors when building so this is easy to miss!

My specific case was the one described by E. van Putten's answer , where Lib screws up when given a .res file as input. More precisely, it ends up writing the path of a temporary file into the .tlog file that is used for its subsequent up-to-date checks (at which point said file is long gone).

Until this is fixed, I've written a crude MSBuild target that is sequenced right after Lib and filters out nonexistent paths from the generated .tlog file.

<!--
This removes the broken temporary file paths that Lib.exe
puts in tlog files when it processes a .rc file.
See https://stackoverflow.com/q/74536502/3233393.
-->
<Target
    Name="BugfixTempFilesInLibTlogs"
    AfterTargets="Lib"
    Condition="Exists('$(TLogLocation)Lib-link-cvtres.write.1.tlog')"
>
    <ReadLinesFromFile
        File="$(TLogLocation)Lib-link-cvtres.write.1.tlog"
    >
        <Output TaskParameter="Lines" ItemName="_LibWriteTlogLines" />
    </ReadLinesFromFile>

    <!--
    Insane item juggling because MSBuild blows up as soon as one mentions `%(FullPath)`
    for something that is not actually a path, such as the first line
    from the .tlog file (which is of the form `^<file>|</file>|...`)
    -->
    <ItemGroup>
        <_LibWriteTlogLinesToRemove Include="@(_LibWriteTlogLines)" />
        <_LibWriteTlogLinesToRemove
            Remove="@(_LibWriteTlogLinesToRemove)"
            Condition="$([System.String]::new('%(Identity)').StartsWith('^'))"
        />
        <_LibWriteTlogLinesToRemove Remove="@(_LibWriteTlogLinesToRemove->Exists())" />
        
        <_LibWriteTlogLines Remove="@(_LibWriteTlogLinesToRemove)" />
    </ItemGroup>
    
    <WriteLinesToFile
        Condition="'@(_LibWriteTlogLinesToRemove)' != ''"
        File="$(TLogLocation)Lib-link-cvtres.write.1.tlog"
        Lines="@(_LibWriteTlogLines)"
        Overwrite="true"
    />
    
    <ItemGroup>
        <_LibWriteTlogLines Remove="@(_LibWriteTlogLines)" />
        <_LibWriteTlogLinesToRemove Remove="@(_LibWriteTlogLinesToRemove)" />
    </ItemGroup>
</Target>

The .tlog file's name seems to change depending on the input to Lib , so make sure that it matches your case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM