dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.65k stars 1.06k forks source link

Publishing native AOT fails on Fedora 40, Documentation suggests packages only for Ubuntu #42335

Open photex opened 1 month ago

photex commented 1 month ago

Describe the bug

I've seen #37995 and the solution doesn't generally apply to Fedora 40. The dotnet documentation is unfortunately Ubuntu specific and would not apply to RHEL distros or Fedora.

Instead you need to install zlib-ng-devel, and zlib-ng-compat-devel.

To Reproduce

chipc@fedora:~/workspaces/slowgames$ mkdir testproj
chipc@fedora:~/workspaces/slowgames$ cd testproj
chipc@fedora:~/workspaces/slowgames/testproj$ dotnet new console
The template "Console App" was created successfully.

Processing post-creation actions...
Restoring /home/chipc/workspaces/slowgames/testproj/testproj.csproj:
  Determining projects to restore...
  Restored /home/chipc/workspaces/slowgames/testproj/testproj.csproj (in 224 ms).
Restore succeeded.
chipc@fedora:~/workspaces/slowgames/testproj$ dotnet publish -c Release -r linux-x64 -p:PublishAOT=true
MSBuild version 17.8.5+b5265ef37 for .NET
  Determining projects to restore...
  Restored /home/chipc/workspaces/slowgames/testproj/testproj.csproj (in 406 ms).
  testproj -> /home/chipc/workspaces/slowgames/testproj/bin/Release/net8.0/linux-x64/testproj.dll
  Generating native code
  /usr/bin/ld.bfd: cannot find -lz: No such file or directory
collect2 : error : ld returned 1 exit status [/home/chipc/workspaces/slowgames/testproj/testproj.csproj]
/home/chipc/.nuget/packages/microsoft.dotnet.ilcompiler/8.0.5/build/Microsoft.NETCore.Native.targets(366,5): error MSB3073: The command ""gcc" "obj/Release/net8.0/linux-x64/native/testproj.o" -o "bin/Release/net8.0/linux-x64/native/testproj" -Wl,--version-script=obj/Release/net8.0/linux-x64/native/testproj.exports -Wl,--export-dynamic -gz=zlib -fuse-ld=bfd /home/chipc/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.5/sdk/libbootstrapper.o /home/chipc/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.5/sdk/libRuntime.WorkstationGC.a /home/chipc/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.5/sdk/libeventpipe-disabled.a /home/chipc/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.5/sdk/libstdc++compat.a /home/chipc/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.5/framework/libSystem.Native.a /home/chipc/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.5/framework/libSystem.Globalization.Native.a /home/chipc/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.5/framework/libSystem.IO.Compression.Native.a /home/chipc/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.5/framework/libSystem.Net.Security.Native.a /home/chipc/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.5/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. [/home/chipc/workspaces/slowgames/testproj/testproj.csproj]
chipc@fedora:~/workspaces/slowgames/testproj$ sudo dnf install zlib-ng-compat-devel
Last metadata expiration check: 0:54:44 ago on Wed 24 Jul 2024 09:44:06 AM CEST.
Dependencies resolved.
========================================================================================================================================
 Package                                  Architecture               Version                          Repository                   Size
========================================================================================================================================
Installing:
 zlib-ng-compat-devel                     x86_64                     2.1.7-1.fc40                     updates                      38 k

Transaction Summary
========================================================================================================================================
Install  1 Package

Total download size: 38 k
Installed size: 107 k
Is this ok [y/N]: y
Downloading Packages:
zlib-ng-compat-devel-2.1.7-1.fc40.x86_64.rpm                                                            489 kB/s |  38 kB     00:00
----------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                    62 kB/s |  38 kB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                1/1
  Installing       : zlib-ng-compat-devel-2.1.7-1.fc40.x86_64                                                                       1/1
  Running scriptlet: zlib-ng-compat-devel-2.1.7-1.fc40.x86_64                                                                       1/1

Installed:
  zlib-ng-compat-devel-2.1.7-1.fc40.x86_64

Complete!
chipc@fedora:~/workspaces/slowgames/testproj$ dotnet publish -c Release -r linux-x64 -p:PublishAOT=true
MSBuild version 17.8.5+b5265ef37 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  testproj -> /home/chipc/workspaces/slowgames/testproj/bin/Release/net8.0/linux-x64/testproj.dll
  testproj -> /home/chipc/workspaces/slowgames/testproj/bin/Release/net8.0/linux-x64/publish/

Further technical details

.NET SDK:
 Version:           8.0.105
 Commit:            eae90abaaf
 Workload version:  8.0.302-baseline.24280.2

Runtime Environment:
 OS Name:     fedora
 OS Version:  40
 OS Platform: Linux
 RID:         fedora.40-x64
 Base Path:   /usr/lib64/dotnet/sdk/8.0.105/

.NET workloads installed:
 Workload version: 8.0.302-baseline.24280.2
There are no installed workloads to display.

Host:
  Version:      8.0.5
  Architecture: x64
  Commit:       087e15321b

.NET SDKs installed:
  8.0.105 [/usr/lib64/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.5 [/usr/lib64/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.5 [/usr/lib64/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/usr/lib64/dotnet]

global.json file:
  Not found

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

Download .NET:
  https://aka.ms/dotnet/download
dotnet-issue-labeler[bot] commented 1 month ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

dotnet-issue-labeler[bot] commented 1 month ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.