.Net 7.0 AOT /usr/bin/ld: cannot find -lz
命令:
sudo dotnet publish -c Release
报错内容:
MSBuild version 17.4.0+18d5aef85 for .NET
Determining projects to restore...
All projects are up-to-date for restore.
oschina2022 -> /mnt/d/GitHub/oschina2022/oschina2022/bin/Release/net7.0/linux-x64/oschina2022.dll
/usr/bin/ld: cannot find -lz
collect2 : error : ld returned 1 exit status [/mnt/d/GitHub/oschina2022/oschina2022/oschina2022.csproj]
/usr/share/dotnet/sdk/7.0.101/Sdks/Microsoft.DotNet.ILCompiler/build/Microsoft.NETCore.Native.targets(346,5): error MSB3073: The command ""gcc" "obj/Release/net7.0/linux-x64/native/oschina2022.o" -o "bin/Release/net7.0/linux-x64/native/oschina2022" /home/maikebing/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.1/sdk/libbootstrapper.a /home/maikebing/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.1/sdk/libRuntime.WorkstationGC.a /home/maikebing/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.1/framework/libSystem.Native.a /home/maikebing/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.1/framework/libSystem.Globalization.Native.a /home/maikebing/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.1/framework/libSystem.IO.Compression.Native.a /home/maikebing/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.1/framework/libSystem.Net.Security.Native.a /home/maikebing/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.1/framework/libSystem.Security.Cryptography.Native.OpenSsl.a -g -Wl,-rpath,'$ORIGIN' -Wl,--build-id=sha1 -Wl,--as-needed -pthread -lstdc++ -ldl -lm -lz -lrt -pie -Wl,-z,relro -Wl,-z,now -Wl,--discard-all -Wl,--gc-sections" exited with code 1. [/mnt/d/GitHub/oschina2022/oschina2022/oschina2022.csproj]
解决方法:
sudo apt-get install zlib1g-dev
yum install zlib-devel
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~