Mirror site is read only www.netnr.com
netnr 2023-12-08 17:15:41 2024-03-13 08:23:11 👁176 💬0

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 --version

# Debian 查看 libc6
dpkg -l libc6

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


链接