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.
相关推荐
小年糕是糕手35 分钟前
【C++同步练习】类和对象(一)
java·开发语言·javascript·数据结构·c++·算法·排序算法
txxzjmzlh36 分钟前
类和对象(下)
开发语言·c++
小年糕是糕手36 分钟前
【C++同步练习】类和对象(二)
java·开发语言·javascript·数据结构·c++·算法·ecmascript
xixixi7777737 分钟前
解析常见的通信流量和流量分析
运维·开发语言·网络·安全·php·通信·流量
csdn_aspnet39 分钟前
用Python抓取ZLibrary元数据
开发语言·python·zlibrary
天下无敌笨笨熊40 分钟前
kotlin常用语法点理解
android·开发语言·kotlin
hazhanglvfang1 小时前
使用curl测试java后端post接口
java·开发语言
杀死那个蝈坦1 小时前
Lua核心认知
开发语言·lua
量子炒饭大师1 小时前
David自习刷题室——【蓝桥杯刷题备战】乘法表
c语言·c++·git·职场和发展·蓝桥杯·github·visual studio