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.
相关推荐
咖啡の猫18 小时前
Python字典推导式
开发语言·python
leiming618 小时前
C++ vector容器
开发语言·c++·算法
SystickInt18 小时前
C语言 strcpy和memcpy 异同/区别
c语言·开发语言
CS Beginner18 小时前
【C语言】windows下编译mingw版本的glew库
c语言·开发语言·windows
FJW02081419 小时前
Python_work4
开发语言·python
大学生资源网19 小时前
java毕业设计之儿童福利院管理系统的设计与实现(源码+)
java·开发语言·spring boot·mysql·毕业设计·源码·课程设计
JasmineWr19 小时前
JVM栈空间的使用和优化
java·开发语言
Poetinthedusk19 小时前
C#实现图片统一位深
开发语言·c#
吴佳浩 Alben20 小时前
Python入门指南(四)
开发语言·后端·python
一然明月20 小时前
QT之基础控件
开发语言·qt