Centos7部署.net8和升级libstdc++

最近有一个系统需要在centos7.9平台上部署,而且需要用到.net8。

然后就按照网上的文章下载了一个二进制包,设置环境变量,运行dodnet报错,centos7.9的依赖不支持。

wget -P /tgz/ https://builds.dotnet.microsoft.com/dotnet/Sdk/8.0.416/dotnet-sdk-8.0.416-linux-x64.tar.gz

shell 复制代码
[root@testmysqldotnet]# pwd
/app/dotnet
[root@testmysqldotnet]# ls -lh
-rwxr-xr-x. 1 1000 1000  67K 10月 28 05:32 dotnet
drwxrwxr-x. 3 1000 1000   17 10月 28 05:42 host
-rw-rw-r--. 1 1000 1000 1.1K 10月 28 05:15 LICENSE.txt
drwxrwxr-x. 6 1000 1000  150 10月 28 22:51 packs
drwxrwxr-x. 3 1000 1000   21 10月 28 22:51 sdk
drwxrwxr-x. 3 1000 1000   21 10月 28 22:51 sdk-manifests
drwxrwxr-x. 4 1000 1000   67 10月 28 22:51 shared
drwxrwxr-x. 3 1000 1000   20 10月 28 22:51 templates
-rw-rw-r--. 1 1000 1000  93K 10月 28 05:15 ThirdPartyNotices.txt
[root@testmysqldotnet]# ./dotnet -v
./dotnet: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by ./dotnet)
./dotnet: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./dotnet)

看了很多教程,基本上就这几点解决方法

  1. 升级操作系统,我要能升级就不会来这问了

    yum升级libstdc++,但是就是不告诉你yum源在哪,怎么配置。而且大都是AI生成的LA JI文章。而且升级底层库对系统有一定影响,某些系统服务(如 systemd、dbus)可能依赖旧 ABI。

  2. 使用docker,没有原生二进制部署方便

这里我参考这篇文章 https://zhuanlan.zhihu.com/p/498529973

,编译新版的libstdc++,然后使用 rpath,或更现代的 $ORIGIN + RUNPATH,这样比全局替换 /usr/lib64/libstdc++.so.6 更稳定可靠,影响最小。因为只影响目标程序,不影响系统其他部分

1.下载源码

复制代码
wget http://ftp.gnu.org/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz

2.编译gcc/libstdc++

复制代码
cd gcc-7.3.0
./contrib/download_prerequisites

3.配置生成Makefile

复制代码
mkdir build;cd build

../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib

4.执行编译,编译时间较长,大约1小时,建议使用多线程编译,再加上nohup放到后台执行

复制代码
nohup make -j 8 2>&1 >> make.log &

5.编译日志我这里是12mb,比较大。

复制代码
[root@testmysqlbuild]# pwd
/tgz/gcc-7.3.0/build
[root@testmysqlbuild]# ll -h make.log 
-rw-r--r--. 1 root root 11M 12月  2 13:52 make.log

6.使用find在编译目录找到产物,这个文件libstdc++.so.6.0.24放到/app/libs/libstdc++.so.6.0.24,然后创建软连接。

shel 复制代码
[root@testmysqlbuild]# ll `find /tgz/ -name libstdc++.so*`
lrwxrwxrwx. 1 root root       19 12月  2 13:47 /tgz/gcc-7.3.0/build/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so -> libstdc++.so.6.0.24
lrwxrwxrwx. 1 root root       19 12月  2 13:47 /tgz/gcc-7.3.0/build/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6 -> libstdc++.so.6.0.24
-rwxr-xr-x. 1 root root 11506368 12月  2 13:47 /tgz/gcc-7.3.0/build/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.24
lrwxrwxrwx. 1 root root       19 12月  2 13:40 /tgz/gcc-7.3.0/build/stage1-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so -> libstdc++.so.6.0.24
lrwxrwxrwx. 1 root root       19 12月  2 13:40 /tgz/gcc-7.3.0/build/stage1-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6 -> libstdc++.so.6.0.24
-rwxr-xr-x. 1 root root 11506368 12月  2 13:40 /tgz/gcc-7.3.0/build/stage1-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.24
lrwxrwxrwx. 1 root root       19 12月  2 13:51 /tgz/gcc-7.3.0/build/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so -> libstdc++.so.6.0.24
lrwxrwxrwx. 1 root root       19 12月  2 13:51 /tgz/gcc-7.3.0/build/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6 -> libstdc++.so.6.0.24
-rwxr-xr-x. 1 root root 11506368 12月  2 13:51 /tgz/gcc-7.3.0/build/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.24
复制代码
[root@testmysqllibs]# ln -sf libstdc++.so.6.0.24 libstdc++.so.6         ^C
[root@testmysqllibs]# pwd
/app/dotnet-8.0.22/libs
[root@testmysqllibs]# ls
libstdc++.so.6.0.24
[root@testmysqllibs]# ln -sf libstdc++.so.6.0.24 libstdc++.so.6

7.安装修改程序。(使用阿里centos7的yum就够了)

复制代码
sudo yum install -y patchelf || sudo dnf install -y patchelf

# 给 dotnet 二进制文件添加 RUNPATH:指向 $ORIGIN/libs
patchelf --set-rpath '$ORIGIN/libs' dotnet

# 验证是否成功
readelf -d dotnet | grep -E 'RPATH|RUNPATH'
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/libs]

8.再次测试,成功解决

shell 复制代码
[root@testmysqldotnet-8.0.22]# ./dotnet -h

Usage: dotnet [host-options] [path-to-application]

path-to-application:
  The path to an application .dll file to execute.

host-options:
  --additionalprobingpath <path>  Path containing probing policy and assemblies to probe for.
  --depsfile <path>               Path to <application>.deps.json file.
  --runtimeconfig <path>          Path to <application>.runtimeconfig.json file.
  --fx-version <version>          Version of the installed Shared Framework to use to run the application.
  --roll-forward <value>          Roll forward to framework version (LatestPatch, Minor, LatestMinor, Major, LatestMajor, Disable)
  --additional-deps <path>        Path to additional deps.json file.
  --list-runtimes                 Display the installed runtimes
  --list-sdks                     Display the installed SDKs

Common Options:
  -h|--help                       Displays this help.
  --info                          Display .NET information.
相关推荐
椒颜皮皮虾྅15 小时前
让文档不止于文字:DeploySharp + PP-Structure,打通版面分析与表格重建
开发语言·学习·c#·.net·cuda
玩泥巴的15 小时前
可能是最现代化的微信生态 .NET 服务端 SDK
ai·微信·.net·aot
Eider199815 小时前
Python基础知识之并发相关-2
开发语言·前端·python
第九序言T15 小时前
Python 数据处理进阶(二十二)用 Pandas 做一次完整的用户行为分析
开发语言·python·数据分析·pandas
云和数据.ChenGuang15 小时前
再论深拷贝和浅拷贝
开发语言·人工智能·python·1024程序员节
悠仁さん15 小时前
【C++】set map 使用
java·前端·c++
艾莉丝努力练剑15 小时前
【AI大模型接入SDK】ChatServer问题修复
c++·学习·ai·大模型·sdk
扶尔魔ocy16 小时前
【QT C++】常用设计模式
c++·设计模式
晚风予卿云月16 小时前
【C++高并发内存池】 2.ThreadCache设计
开发语言·c++·高并发内存池·tcmalloc
Dovis(誓平步青云)16 小时前
拖动关键帧角色就抽动,动画编辑器怎样补齐中间状态
开发语言·前端·javascript·机器学习·编辑器