0. 前言
gcc(GNU Compiler Collection)是GNU项目标一部分,它是一个支持多种编程语言的编译器聚集,但最常用的是作为C和C++的编译器。GCC能够编译、汇编和链接C、C++、Objective-C、Fortran、Ada、Go以及D等多种语言的程序。它因其跨平台性、高效性和机动性而受到广泛的欢迎和使用。
我的系统类型规格如下,openeuler属于redhat/centos系列。Ubuntu系列主机本文仅供参考。
- [root@localhost ~]# cat /etc/redhat-release
- BigCloud Enterprise Linux For Euler release 21.10 (LTS-SP2)
- [root@localhost ~]# cat /etc/os-release
- NAME="BigCloud Enterprise Linux"
- VERSION="21.10 (LTS-SP2)"
- ID="bclinux"
- VERSION_ID="21.10"
- PRETTY_NAME="BigCloud Enterprise Linux For Euler 21.10 LTS"
- ANSI_COLOR="0;31"
- [root@localhost ~]# free -g
- total used free shared buff/cache available
- Mem: 15 0 14 0 0 14
- Swap: 7 0 7
复制代码 近来要在BClinux for openeuler上安装mysql8.0结果各种报错,缺少很多依赖。惋惜系统自带的yum源要么就是没有这个安装包,要么就是软件版本不符合要求。所以只能选择源码编译安装。当前系统gcc版本为7.3.0,要升级到10以上.
安装gcc前须要安装GMP、MPFR、MPC这三个依赖库
- # 查看当前系统gcc版本
- root@localhost ~]# gcc --version
- gcc (GCC) 7.3.0
- Copyright © 2017 Free Software Foundation, Inc.
- 本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
- 包括没有适销性和某一专用目的下的适用性担保。
复制代码 1. 安装前预备工作
假如须要再root下直接安装,请参考文章最后的root下编译安装gcc脚本
1.1 创建weihu用户
养成良好安装习惯,不使用root直接安装。假如须要再root下安装,请略过本文1.1小节即可
这里我们注册一个weihu用户,并赋予维护用户sudo权限。然后使用weihu用户安装
- # 创建weihu用户
- [root@localhost ~]# useradd -m weihu
- # 设置weihu的密码
- [root@localhost ~]# passwd weihu
- 更改用户 weihu 的密码 。
- 新的 密码:
- 重新输入新的 密码:
- passwd:所有的身份验证令牌已经成功更新。
复制代码 赋予weihu用户sudo权限
- # 编辑 /etc/sudoers文件 ,找到下面的一行内容
- # root ALL=(ALL) ALL
- [root@localhost ~]# vi /etc/sudoers
复制代码
在root ALL=(ALL) ALL这一行下面添加
保存退出
接下来的所有操作均在weihu用户下面操作
- # 登录weihu用户
- [root@localhost ~]# su - weihu
复制代码 1.2 安装依赖包
编译安装gcc之前,须要安装GMP、MPFR、MPC三个依赖。且三个依赖包的安装次序由先后。同样,我们也须要分别编译安装(使用yum安装的版本较低,报错较多)
安装之前,先建个文件夹用于存放源码
- # 将
- [weihu@localhost ~]$ mkdir /home/weihu/soft
- [weihu@localhost ~]$ cd /home/weihu/soft
复制代码 1.2.1 安装 GMP
CMP下载网址:https://gcc.gnu.org/pub/gcc/infrastructure/
这里我们下周最新的版本6.2.1版本
可以下载到本地再上传到Linux主机,若Linux主机可以访问公网,也可以通过wget方向直接下载到Linux主机。
这里我选择第二种方法。
- # 下载gmp-6.2.1.tar.bz2源码
- [weihu@localhost ~]$ cd /home/weihu/soft/
- [weihu@localhost soft]$ wget https://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.2.1.tar.bz2
- # 解压gmp-6.2.1.tar.bz2源码
- [weihu@localhost soft]$ tar -xvf gmp-6.2.1.tar.bz2
- # 进入解压后的文件夹
- [weihu@localhost soft]$ cd gmp-6.2.1/
- # #创建并进入安装目录
- [weihu@localhost gmp-6.2.1]$ mkdir build
- [weihu@localhost gmp-6.2.1]$ cd build
- [weihu@localhost build]$
- # #配置安装
- [weihu@localhost build]$ ../configure -prefix=/usr/local/gmp-6.2.1
- # 编译
- weihu@localhost build]$ make -j$(nproc)
- # 安装
- [weihu@localhost build]$ sudo make install
复制代码 如许就把gmp安装在/usr/local/gmp-6.2.1路径下
在进行编译安装的时间。我用的命令为 make -j$(nproc)
使用 -j 选项可以指定同时运行的作业(即编译使命)的最大数量。假如 -j 背面跟的是一个数字,那么 make 会尝试同时运行指定命量的作业。假如不跟数字,大概跟的是 0,make 会尝试同时运行尽可能多的作业。
1.2.2 安装MPFR
MPFR下载网址:https://gcc.gnu.org/pub/gcc/infrastructure/
本次,我们选择MPFR版本为4.1.0
- # 下载源码
- [weihu@localhost ~]$ cd /home/weihu/soft/
- [weihu@localhost soft]$ wget https://gcc.gnu.org/pub/gcc/infrastructure/mpfr-4.1.0.tar.bz2
- # 解压mpfr-4.1.0.tar.bz2
- [weihu@localhost soft]$ tar -xvf mpfr-4.1.0.tar.bz2
- # 进入解压后的文件
- [weihu@localhost soft]$ cd mpfr-4.1.0/
- # 新建构建文件夹并进入
- weihu@localhost mpfr-4.1.0]$ mkdir build
- weihu@localhost mpfr-4.1.0]$ cd build
- # 配置安装
- [weihu@localhost build]$ ../configure --prefix=/usr/local/mpfr-4.1.0 --with-gmp=/usr/local/gmp-6.2.1
- # 编译
- [weihu@localhost build]$ make -j$(nproc)
- # 安装
- [weihu@localhost build]$ sudo make install
复制代码 如许就把mpfr-4.1.0安装在/usr/local/mpfr-4.1.0路径下
1.2.3 安装MPC
PC下载网址:https://gcc.gnu.org/pub/gcc/infrastructure/
本次,我们选择MPC版本为1.2.1
- # 下载源码
- [weihu@localhost soft]$ cd /home/weihu/soft
- [weihu@localhost soft]$ wget https://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.2.1.tar.gz
- #解压源码
- [weihu@localhost soft]$ tar -xvf mpc-1.2.1.tar.gz
- # 进入解压后的文件夹
- [weihu@localhost soft]$ cd mpc-1.2.1/
- # 创建构建文件夹并进入
- [weihu@localhost mpc-1.2.1]$ mkdir build
- [weihu@localhost mpc-1.2.1]$ cd build
- #配置安装
- [weihu@localhost build]$ ../configure --prefix=/usr/local/mpc-1.2.1 --with-gmp=/usr/local/gmp-6.2.1 --with-mpfr=/usr/local/mpfr-4.1.0
- # 编译
- [weihu@localhost build]$ make -j$(nproc)
- # 安装
- [weihu@localhost build]$ sudo make install
复制代码 如许就把mpc-1.2.1安装在/usr/local/mpc-1.2.1路径下
2. gcc10.0.1版本安装
gcc源码下载地址:https://gcc.gnu.org/pub/gcc/releases/
本次我们选择gcc-10.1.0.tar.gz安装
- # 下载源码
- [weihu@localhost soft]$ cd /home/weihu/soft
- [weihu@localhost soft]$ wget https://gcc.gnu.org/pub/gcc/releases/gcc-10.1.0/gcc-10.1.0.tar.gz
- # 解压源码并进入
- [weihu@localhost soft]$ tar -xvzf gcc-10.1.0.tar.gz
- [weihu@localhost soft]$ cd gcc-10.1.0/
- # 创建构建文件夹并进入
- [weihu@localhost gcc-10.1.0]$ mkdir build
- [weihu@localhost gcc-10.1.0]$ cd build
- # 配置安装
- [weihu@localhost build]$ ../configure --prefix=/usr/local/gcc-10.1.0 -enable-threads=posix -disable-checking -disable-multilib -enable-languages=c,c++ --with-gmp=/usr/local/gmp-6.2.1 --with-mpfr=/usr/local/mpfr-4.1.0 --with-mpc=/usr/local/mpc-1.2.1
- # 编译(时间较长)
- [weihu@localhost build]$ make -j$(nproc)
- # 安装
- [weihu@localhost build]$ sudo make install
复制代码 gcc至此安装成功,然后我们将gcc添加进入系统环境变量
- # 软链接
- [weihu@localhost ~]$ sudo ln -s /usr/local/gcc-10.1.0/bin/gcc gcc
- [weihu@localhost ~]$ sudo ln -s /usr/local/gcc-10.1.0/bin/g++ g++
- [weihu@localhost ~]$ export PATH=/usr/local/gcc-10.1.0/bin:$PATH
复制代码 查看gcc版本
- [weihu@localhost ~]$ gcc --version
- gcc (GCC) 10.1.0
- Copyright (C) 2020 Free Software Foundation, Inc.
- This is free software; see the source for copying conditions. There is NO
- warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- [weihu@localhost ~]$
复制代码
3. 报错办理
3. 1. wget下载报错
- [weihu@localhost soft]$ wget https://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.2.1.tar.bz2
- --2024-03-28 00:17:13-- https://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.2.1.tar.bz2
- Resolving gcc.gnu.org (gcc.gnu.org)... 8.43.85.97, 2620:52:3:1:0:246e:9693:128c
- Connecting to gcc.gnu.org (gcc.gnu.org)|8.43.85.97|:443... connected.
- ERROR: The certificate of ‘gcc.gnu.org’ is not trusted.
- ERROR: The certificate of ‘gcc.gnu.org’ is not yet activated.
- The certificate has not yet been activated
复制代码 办理方法·
- ## 绕过 SSL 验证
- wget --no-check-certificate https://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.2.1.tar.bz2
复制代码 4. 参考文档
- https://cloud.tencent.com/developer/article/2112576
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |