GLIBCXX
经实践,编译为 NativeAOT 后可直接运行,无视 GLIBCXX 版本低的问题
CentOS 7 默认的版本较低,需要升级 libstdc++6
/lib64/libstdc++.so.6: version GLIBCXX_3.4.20 not found
/lib64/libstdc++.so.6: version GLIBCXX_3.4.21 not found
搜索已有版本,CentOS 7.6.1810 搜索出来最高版本为 GLIBCXX_3.4.19
strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX
更多查看方式
# glibc 的版本号 ldd (GNU libc) 2.17
ldd --version
# Debian 查看 libc6
dpkg -l libc6
Updating .NET Linux Build for .NET 8
https://github.com/dotnet/runtime/issues/83428
替换 CentOS7 so 文件
# 下载 lib64 并解压
wget https://adbin.top/packages/lib64.tar.gz
tar -xzf lib64.tar.gz
# 替 /usr/lib64/libstdc++.so.6
cd /lib64
cp libstdc++.so.6.0.25 cd /usr/lib64
# 重新 link
cd /usr/lib64
rm libstdc++.so.6
ln -s libstdc++.so.6.0.25 libstdc++.so.6
ref: https://www.cnblogs.com/objectnull/p/17873788
NativeAOT
System.Text.Json 组件得使用源生成 source generation
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureCelsius { get; set; }
public string Summary { get; set; }
}
[JsonSerializable(typeof(WeatherForecast))]
internal partial class SourceGenerationContext : JsonSerializerContext
{
}
/// <summary>
/// 转为 JSON (this 就是实体对象)
/// </summary>
/// <returns></returns>
public string ToJSON() => JsonSerializer.Serialize(this, SourceGenerationContext.Default.WeatherForecast);
ref: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation
版本支持情况
https://github.com/dotnet/core/blob/main/release-notes/6.0/supported-os.md
https://github.com/dotnet/core/blob/main/release-notes/7.0/supported-os.md
https://github.com/dotnet/core/blob/main/release-notes/8.0/supported-os.md
https://github.com/dotnet/core/blob/main/release-notes/9.0/supported-os.md
https://github.com/dotnet/core/blob/main/release-notes/10.0/supported-os.md