Search code examples
c#.netlinuxubuntunuget

ld.bfd: cannot find -lz: No such file or directory


I'm getting this error when I try to compile a native C# lib in Ubuntu 22.04.3 LTS (Jammy Jellyfish), it was not there in 20.4.

The command used; dotnet publish -r linux-x64 -c Release -p:PublishAot=true

Error;

/usr/bin/ld.bfd: cannot find -lz: No such file or directory

collect2 : error : ld returned 1 exit status [test.csproj] /root/.nuget/packages/microsoft.dotnet.ilcompiler/8.0.2/build/Microsoft.NETCore.Native.targets(367,5): error MSB3073: The command ""gcc" "test.o" -o "test.so" -Wl,--version-script=obj/Release/net8.0/linux-x64/native/test.exports -Wl,--export-dynamic -gz=zlib -fuse-ld=bfd libf.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.2/sdk/libbootstrapperdll.o /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.2/sdk/libRuntime.WorkstationGC.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.2/sdk/libeventpipe-disabled.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.2/sdk/libstdc++compat.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.2/framework/libSystem.Native.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.2/framework/libSystem.Globalization.Native.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.2/framework/libSystem.IO.Compression.Native.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.2/framework/libSystem.Net.Security.Native.a /root/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/8.0.2/framework/libSystem.Security.Cryptography.Native.OpenSsl.a -g -Wl,-rpath,'$ORIGIN' -Wl,--build-id=sha1 -Wl,--as-needed -Wl,-e0x0 -pthread -ldl -lz -lrt -lm -shared -Wl,-z,relro -Wl,-z,now -Wl,--eh-frame-hdr -Wl,--discard-all -Wl,--gc-sections" exited with code 1.

Also if I cd into /usr/bin and try ld.bfd -lz I get the following error again;

ld.bfd: cannot find -lz: No such file or directory

While if I run the same in a machine that compiles the lib without error I get the following;

ld.bfd: warning: cannot find entry symbol _start; not setting start address

Which makes me think that some lib or component is missing in the Ubuntu that I'm getting the error message with. Does anyone have any idea as to what that might be?


Solution

  • The issue was a missing zlib1g-dev lib. Installing it solved it.