编译安装gcc
1.下载软件包
Gcc 可以到官网下载,也可以看这(http://mirror.linux-ia64.org/gnu/gcc/releases/),同时,安装 Gcc 需要五个依赖,分别是:m4, gmp, mpfr, mpc, isl。
2.安装依赖
2.1安装m4
tar -zxvf /to your path/m4-1.4.19.tar.gz -C /to your path/
cd /to your path/m4-1.4.19
./configure --prefix=/to your path/m4/1.4.19
make
make install
声明环境变量
export PATH=/to your path/m4/1.4.19/bin:$PATH
否则可能报错:configure: error: No usable m4 in $PATH or /usr/5bin 说找不到m4
2.2安装gmp
tar -xf /to your path/gmp-6.2.1.tar.xz -C /to your path/
cd /to your path/gmp-6.2.1
./configure --prefix=/to your path/gmp/6.2.1
make
make check
make install
2.3安装mpfr
tar -zxvf /to your path/mpfr-4.1.0.tar.gz -C /to your path/
cd /to your path/mpfr-4.1.0
./configure --prefix=/to your path/mpfr/4.1.0 --with-gmp=/to your path/gmp/6.2.1
make
make check
make install
2.4安装mpc
tar -zxvf /to your path/mpc-1.2.1.tar.gz -C /to your path/
cd /to your path/mpc-1.2.1
./configure --prefix=/to your path/mpc/1.2.1 --with-gmp=/to your path/gmp/6.2.1 --with-mpfr=/to your path/mpfr/4.1.0
make
make check
make install
2.5安装isl
tar -jxvf /to your path/isl-0.24.tar.bz2 -C /to your path/
cd /to your path/isl-0.24
./configure --prefix=/to your path/isl/0.24/ --with-gmp-prefix=/to your path/gmp/6.2.1/
make
make check
make install
安装完成后,将五个依赖库文件写入到环境变量LD_LIBRARY_PATH中去
export LD_LIBRARY_PATH=/to your path/m4/1.4.19:/to your path/mpc/1.2.1/lib:/to your path/gmp/6.2.1/lib:/to your path/mpfr/4.1.0/lib:/to your path/isl/0.24/lib:$LD_LIBRARY_PATH
3.安装gcc
tar -zxvf /to your path/gcc-11.2.0.tar.gz -C /to your path/gcc/11.2.0
cd /to your path/gcc-11.2.0
./configure --prefix=/to your path/gcc/11.2.0 --enable-threads=posix --enable-languages=c,c++,fortran --disable-checking --disable-multilib --disable-multilib --disable-libcc1cd --with-gmp=/to your path/gmp/6.2.1 --with-mpfr=/to your path/mpfr/4.1.0 --with-mpc=/to your path/mpc/1.2.1 --with-isl=/to your path/isl/0.24
make -j
make install
编译安装时间较长,请耐心等待
export PATH=/to your path/gcc/bin:$PATH
4.一键安装脚本(自行修改参数)
#!/usr/bin/bash
set -e
set -v on
### 本文件为 gcc 的安装脚本,在执行本脚本之前,需要修改本文件中的一些配置
### 当前时间:2024年6月25日16:29:38
### 开始指定/配置
## 指定 gcc 的安装包路径(默认与本脚本在同一目录)
gcc_pkg_dir=$(dirname $(readlink -f "$0"))
## 指定 gcc 的版本号
gcc_version=7.3.0
## 指定 gcc 的 build 目录【可选】(默认与安装包在同一路径)
gcc_build_dir=/to/your/path
## 指定 gcc 的安装目录
gcc_install_dir=/to/your/path/gcc/${gcc_version}
## 指定 gcc 的五个依赖的安装包目录【可选】(默认与本脚本在同一目录)
gcc_rely_pkg_dir=$(dirname $(readlink -f "$0"))
## 指定这五个依赖的 build 目录【可选】(默认与安装包在同一路径)
gcc_rely_build_dir=${gcc_rely_pkg_dir}/build
## 指定这五个依赖的安装目录
gcc_rely_install_dir=/to/your/path/gcc/${gcc_version}/.rely
## 指定 m4 的版本号
m4_version=1.4.19
## 指定 gmp 的版本号
gmp_version=6.2.1
## 指定 mpfr 的版本号
mpfr_version=4.1.0
## 指定 mpc 的版本号
mpc_version=1.2.1
## 指定 isl 的版本号
isl_version=0.15
### 指定完毕,配置完成
### 创建 gcc 的 build 目录
mkdir -p ${gcc_build_dir}
### 创建五个依赖的 build 目录
mkdir -p ${gcc_rely_build_dir}
## 开始安装 m4
tar -zxvf ${gcc_rely_pkg_dir}/m4-${m4_version}.tar.gz -C ${gcc_rely_build_dir}
cd ${gcc_rely_build_dir}/m4-${m4_version}
./configure --prefix=${gcc_rely_install_dir}/m4/${m4_version}
make
make install
export PATH=${gcc_rely_install_dir}/m4/${m4_version}/bin:$PATH
## 安装 m4 完毕
## 开始安装 gmp
tar -xf ${gcc_rely_pkg_dir}/gmp-${gmp_version}.tar.xz -C ${gcc_rely_build_dir}
cd ${gcc_rely_build_dir}/gmp-${gmp_version}
./configure --prefix=${gcc_rely_install_dir}/gmp/${gmp_version}
make
make check
make install
## 安装 gmp 完毕
## 开始安装 mpfr
tar -zxvf ${gcc_rely_pkg_dir}/mpfr-${mpfr_version}.tar.gz -C ${gcc_rely_build_dir}
cd ${gcc_rely_build_dir}/mpfr-${mpfr_version}
./configure --prefix=${gcc_rely_install_dir}/mpfr/${mpfr_version} --with-gmp=${gcc_rely_install_dir}/gmp/${gmp_version}
make
make check
make install
## 安装 mpfr 完毕
## 开始安装 mpc
tar -zxvf ${gcc_rely_pkg_dir}/mpc-${mpc_version}.tar.gz -C ${gcc_rely_build_dir}
cd ${gcc_rely_build_dir}/mpc-${mpc_version}
./configure --prefix=${gcc_rely_install_dir}/mpc/${mpc_version} --with-gmp=${gcc_rely_install_dir}/gmp/${gmp_version} --with-mpfr=${gcc_rely_install_dir}/mpfr/${mpfr_version}
make
make check
make install
## 安装 mpc 完毕
## 开始安装 isl
tar -jxvf ${gcc_rely_pkg_dir}/isl-${isl_version}.tar.bz2 -C ${gcc_rely_build_dir}
cd ${gcc_rely_build_dir}/isl-${isl_version}
./configure --prefix=${gcc_rely_install_dir}/isl/${isl_version} --with-gmp-prefix=${gcc_rely_install_dir}/gmp/${gmp_version}
make
make check
make install
## 安装 isl 完毕
## 将安装得到的库文件路径写入到环境变量 LD_LIBRARY_PATH 中去
export LD_LIBRARY_PATH=${gcc_rely_install_dir}/m4/${m4_version}:${gcc_rely_install_dir}/gmp/${gmp_version}/lib:${gcc_rely_install_dir}/mpfr/${mpfr_version}/lib:${gcc_rely_install_dir}/mpc/${mpc_version}/lib:${gcc_rely_install_dir}/isl/${isl_version}/lib:$LD_LIBRARY_PATH
## 开始安装 gcc
tar -zxvf ${gcc_pkg_dir}/gcc-${gcc_version}.tar.gz -C ${gcc_build_dir}
cd ${gcc_build_dir}/gcc-${gcc_version}
./configure --prefix=${gcc_install_dir} --enable-threads=posix --enable-languages=c,c++,fortran --disable-checking --disable-multilib --disable-multilib --disable-libcc1cd --with-gmp=${gcc_rely_install_dir}/gmp/${gmp_version} --with-mpfr=${gcc_rely_install_dir}/mpfr/${mpfr_version} --with-mpc=${gcc_rely_install_dir}/mpc/${mpc_version} --with-isl=${gcc_rely_install_dir}/isl/${isl_version}
make -j
make install
## 安装完毕
echo "gcc has been installed to " ${gcc_install_dir}
echo `${gcc_install_dir}/bin/gcc -v`
set +e
### END
cd $gcc_install_dir
touch env.sh
echo "export PATH=$gcc_install_dir/bin:\$PATH" >> env.sh
echo "export CPATH=$gcc_install_dir/include:\$CPATH" >> env.sh
echo "export LD_LIBRARY_PATH=$gcc_install_dir/lib:\$LD_LIBRARY_PATH" >> env.sh
echo "export LD_LIBRARY_PATH=$gcc_install_dir/lib64:\$LD_LIBRARY_PATH" >> env.sh
echo "export LIBRARY_PATH=$gcc_install_dir/lib:\$LIBRARY_PATH" >> env.sh
echo "export LIBRARY_PATH=$gcc_install_dir/lib64:\$LIBRARY_PATH" >> env.sh
echo "Command: source ${gcc_install_dir}/env.sh to use gcc-${gcc_version} "
博客:zhouj.club