Skip to content

Publishing Native AOT fails on linux  #37995

@anpin

Description

@anpin

Describe the bug

Publishing net8.0 console app with <PublishAot>true</PublishAot> fails on linux. I've tried both F# and C# on multiple flavors of linux: nixos and docker using mcr.microsoft.com/dotnet/sdk:8.0.101-alpine3.19-amd64 and mcr.microsoft.com/dotnet/sdk:8.0-jammy images.

To Reproduce

Pick your build falvour:

  • nix build github:anpin/dotnet-aot-on-nix
  • docker build https://github.com/anpin/dotnet-aot-on-nix.git
  • (clone the repo, enter its directory and then run) nix develop --command bash build.sh (this runs in the local shell and saves binlog which is already included in the repo)

Exceptions (if any)

MSBuild version 17.8.3+195e7f5a3 for .NET
  Determining projects to restore...
  Restored /app/CsharpAot.csproj (in 20.85 sec).
  CsharpAot -> /app/bin/Release/net8.0/linux-x64/CsharpAot.dll
  Generating native code
  /usr/bin/ld.bfd: cannot find -lz: No such file or directory
collect2 : error : ld returned 1 exit status [/app/CsharpAot.csproj]
/root/.nuget/packages/microsoft.dotnet.ilcompiler/8.0.1/build/Microsoft.NETCore.Native.targets(364,5): error MSB3073: The command ""gcc" "obj/Release/net8.0/linux-x64/native/CsharpAot.o" -o "bin/Release/net8.0/linux-x64/native/CsharpAot" -gz=zlib -fuse-ld=bfd /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.1/sdk/libbootstrapper.o /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.1/sdk/libRuntime.WorkstationGC.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.1/sdk/libeventpipe-disabled.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.1/sdk/libstdc++compat.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.1/framework/libSystem.Native.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.1/framework/libSystem.Globalization.Native.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.1/framework/libSystem.IO.Compression.Native.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.1/framework/libSystem.Net.Security.Native.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.1/framework/libSystem.Security.Cryptography.Native.OpenSsl.a -g -Wl,-rpath,'$ORIGIN' -Wl,--build-id=sha1 -Wl,--as-needed -pthread -ldl -lz -lrt -lm -pie -Wl,-pie -Wl,-z,relro -Wl,-z,now -Wl,--eh-frame-hdr -Wl,--discard-all -Wl,--gc-sections" exited with code 1. [/app/CsharpAot.csproj]
Error: building at STEP "RUN dotnet publish -c Release -o out": while running runtime: exit status 1

Further technical details

.NET SDK:
 Version:           8.0.100
 Commit:            57efcf1350
 Workload version:  8.0.100-manifests.6c33ef20

Runtime Environment:
 OS Name:     nixos
 OS Version:  24.05
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /nix/store/gm3ak3vgrx8qik40cnw28056i38hajsb-dotnet-sdk-8.0.100/sdk/8.0.100/

.NET workloads installed:
 Workload version: 8.0.100-manifests.6c33ef20
There are no installed workloads to display.

Host:
  Version:      8.0.0
  Architecture: x64
  Commit:       5535e31a71

.NET SDKs installed:
  8.0.100 [/nix/store/gm3ak3vgrx8qik40cnw28056i38hajsb-dotnet-sdk-8.0.100/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.0 [/nix/store/gm3ak3vgrx8qik40cnw28056i38hajsb-dotnet-sdk-8.0.100/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.0 [/nix/store/gm3ak3vgrx8qik40cnw28056i38hajsb-dotnet-sdk-8.0.100/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-NativeAOTNative AOT compilationuntriagedRequest triage from a team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions