一:项目名称:Net9API
发布设置:
设置为Linux-64,独立部署:
将发布后的文件拷贝到centos制定文件夹,然后运行:
./Net9API
报错:
./Net9API: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by ./Net9API) ./Net9API: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./Net9API)
这里有一个大胆的推论:
其实运行时需要GLIBCXX_3.4.21文件而已,不需要升级GCC到5.2.0,但一般情况下需要通过升级GCC来获取GLIBCXX_3.4.21文件,另外升级的时候,并不要make install来升级GCC编译后的文件,只需要使用命令make -j8(用8线程编译,加快编译速度)来编译所需的文件,编译完成后,查找GLIBCXX_3.4.21文件:
find . -name "libstdc++.so*"
然后拷贝文件到/usr/lib64:
cp ./x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.21 /usr/lib64
然后删除原来的软链接(或者更新也行),建立新软链接
rm -f libstdc++.so.6 ln -s libstdc++.so.6.0.21 libstdc++.so.6
再次运行NET9API,发现报错:
Couldn't find a valid ICU package installed on the system. Please install libicu (or icu-libs) using your package manager and try again. Alternatively you can set the configuration flag System.Globalization.Invariant to true if you want to run with no globalization support. Please see https://aka.ms/dotnet-missing-libicu for more information. at System.Environment.FailFast(System.Runtime.CompilerServices.StackCrawlMarkHandle, System.String, System.Runtime.CompilerServices.ObjectHandleOnStack, System.String) at System.Environment.FailFast(System.Threading.StackCrawlMark ByRef, System.String, System.Exception, System.String) at System.Environment.FailFast(System.String) at System.Globalization.GlobalizationMode+Settings..cctor() at System.Globalization.CultureData.CreateCultureWithInvariantData() at System.Globalization.CultureData.get_Invariant() at System.Globalization.CultureInfo..cctor() at System.Globalization.CultureInfo.get_CachedCulturesByName() at System.Globalization.CultureInfo.GetCultureInfo(System.String) at System.Reflection.RuntimeAssembly.GetLocale() at System.Reflection.RuntimeAssembly.GetName(Boolean) at Microsoft.Extensions.Hosting.HostBuilder.CreateHostingEnvironment(Microsoft.Extensions.Configuration.IConfiguration) at Microsoft.Extensions.Hosting.HostApplicationBuilder.Initialize(Microsoft.Extensions.Hosting.HostApplicationBuilderSettings, Microsoft.Extensions.Hosting.HostBuilderContext ByRef, Microsoft.Extensions.Hosting.IHostEnvironment ByRef, LoggingBuilder ByRef, MetricsBuilder ByRef) at Microsoft.Extensions.Hosting.HostApplicationBuilder..ctor(Microsoft.Extensions.Hosting.HostApplicationBuilderSettings) at Microsoft.AspNetCore.Builder.WebApplicationBuilder..ctor(Microsoft.AspNetCore.Builder.WebApplicationOptions, System.Action`1<Microsoft.Extensions.Hosting.IHostBuilder>) at Microsoft.AspNetCore.Builder.WebApplication.CreateBuilder(System.String[]) at Program.<Main>$(System.String[])
然后安装网友描述,采用安装组件方法来解决(当然也有其他方法):
Microsoft.ICU.ICU4C.Runtime
并在项目文件添加依赖:
<ItemGroup> <RuntimeHostConfigurationOption Include="System.Globalization.AppLocalIcu" Value="72.1.0.3"/> </ItemGroup>
然后继续运行,发现正常。但需要配置对外访问的接口,在appsettings.json文件中添加配置:
"Kestrel": { "Endpoints": { "http": { "Url": "http://0.0.0.0:5000" } } }
然后开启服务器防火墙,访问:
IP:5000/WeatherForecast/get
注意:如果API启动后控制台输出:Now listening on: http://0.0.0.0:5000说明配置正常,如果显示localhost...则说明对外配置端口错误。
标签:core,libstd,asp,String,System,c++,centos7.9,Extensions,Microsoft From: https://www.cnblogs.com/jizhong/p/18644263