netnr 2023-12-08 17:15:41 👁84 💬0

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

经实践,编译为 NativeAOT 后可直接运行,无视 GLIBCXX 版本低的问题

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


链接