Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NativeAOT] LNK1181: cannot open input file / Code 1181 #1748

Closed
Symbai opened this issue Nov 23, 2021 · 7 comments
Closed

[NativeAOT] LNK1181: cannot open input file / Code 1181 #1748

Symbai opened this issue Nov 23, 2021 · 7 comments
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation

Comments

@Symbai
Copy link

Symbai commented Nov 23, 2021

I'm using VS 2022 and I have Desktop C++ package installed. I have a DLL project with literally nothing in it. Trying to publish always errors with:
dotnet publish /p:NativeLib=Shared -c Release --self-contained -r win-x64

LINK : fatal error LNK1181: cannot open input file 'Version=13.0.0.0,' [C:\Users\User\Documents\Test.File\Test.File.csproj]
C:\Users\User\.nuget\packages\microsoft.dotnet.ilcompiler\7.0.0-alpha.1.21570.2\build\Microsoft.NETCore.Native.targets(360,5): error MSB3073: The command ""C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.31.30818\bin\Hostx64\x64\link.exe "@" obj\Release\net6.0\win-x64\native\link.rsp"" exited with code 1181.
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <PlatformTarget>x64</PlatformTarget>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.DotNet.ILCompiler" Version="7.0.0-*" />
  </ItemGroup>

</Project>
using System.Runtime.InteropServices;

namespace Test.File
{
    public class Class1
    {
        [UnmanagedCallersOnly(EntryPoint = "Test")]
        public static IntPtr Test()
        {
            IntPtr sumPointer = Marshal.StringToHGlobalAnsi("");
            return sumPointer;
        }
    }
}

image

Trying to publish without --self-contained results in:
error NETSDK1102: Assembly sizing is not supported for the selected publishing configuration. Make sure to publish a standalone app.

@Symbai
Copy link
Author

Symbai commented Nov 23, 2021

If I downgrade the IlCompiler version to 6.0.0-rc.1.21420.1 I can successfully build it. But the sample project here in this repo is also targeting .net6 and IlCompiler version 7.0.0-*. Is the sample outdated or is this a bug in newer IlCompiler version?

@jkotas
Copy link
Member

jkotas commented Nov 23, 2021

cannot open input file 'Version=13.0.0.0,'

Could plese you open obj\Release\net6.0\win-x64\native\link.rsp in the text editor and check where the Version=13.0.0.0 string is coming from?

Do the instructions from https://github.com/dotnet/runtimelab/tree/feature/NativeAOT/samples/NativeLibrary work for you? The publish line from those instructions is dotnet publish /p:NativeLib=Shared /p:SelfContained=true -c Release -r win-x64. Note that --self-contained does not have the same effect as /p:SelfContained=true.

@Symbai
Copy link
Author

Symbai commented Nov 24, 2021

It comes from Newtonsoft.Json but I don't reference/use this library at all 🤔

LIBPATH: "Send-VsDevShellTelemetry: The file or assembly" Newtonsoft.Json, Version = 13.0.0.0, Culture = neutral, "
/ LIBPATH: "PublicKeyToken = 30ad4fe6b2a6aeed" or a dependency on it was not found. The system can use the specified "
/ LIBPATH: "Cannot find file."
/ LIBPATH: "In line: 1 character: 168"
/ LIBPATH: "+ ... udio.DevShell.dll '"
/ LIBPATH: "Send-VsDevShellTelemetry -NewInstanceType Cmd"
/ LIBPATH: "}}"
/ LIBPATH: "+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "
/ LIBPATH: "+ CategoryInfo: NotSpecified: (:) [Send-VsDevShellTelemetry], FileNotFoundException"
/ LIBPATH: "+ FullyQualifiedErrorId: System.IO.FileNotFoundException, Microsoft.VisualStudio.DevShell.Commands.SendVsDevShellT"
/ LIBPATH: "elemetryCommand"

Using exactly this line has no effect, it produces the same error: dotnet publish /p:NativeLib=Shared /p:SelfContained=true -c Release -r win-x64

@jkotas
Copy link
Member

jkotas commented Nov 24, 2021

It looks like another manifestation of dotnet/runtime#60061.

Can you try setting VSCMD_SKIP_SENDTELEMETRY=1 in your environment?

@jkotas jkotas added the area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation label Nov 24, 2021
@Symbai
Copy link
Author

Symbai commented Nov 24, 2021

Yep that did the trick. Not sure why it only happens with version 7.0.0-* and with a lower version not. From the referenced issue it sounds like a VS bug?

@jkotas
Copy link
Member

jkotas commented Nov 24, 2021

Yes, it is VS bug that will be fixed in the next VS update.

@jkotas jkotas closed this as completed Nov 24, 2021
@jkotas
Copy link
Member

jkotas commented Nov 24, 2021

Yep that did the trick. Not sure why it only happens with version 7.0.0-*

The older versions did not look for VS 2022. They used VS 2019 that did not have this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation
Projects
None yet
Development

No branches or pull requests

2 participants