Linux环境下, 源码编译安装详解 (编译CMake 3.15 和 gcc 5.3.0 为例)
一. 源码编译安装详解
(待补充)
二. 安装CMake 3.15
1. 查看操作系统版本
[root@mysql80 local]# cat /etc/redhat-releaseCentOS Linux release 7.4.1708 (Core)
2. 下载软件
下载地址:https://cmake.org/download/
软件位置:/software/cmake-3.15.0-rc1.tar.gz
3. 创建安装目录
mkdir /usr/local/cmake-3.15.0
4. 配置安装
(1)切换到软件目录,解压软件包
[root@mysql80 cmake-3.15.0]# cd /software/[root@mysql80 software]# ls -l | grep cmake-3.15.0-rc1.tar.gz -rw-r--r--. 1 root root 9249478 Jun 10 08:32 cmake-3.15.0-rc1.tar.gz[root@mysql80 software]# tar -zxvf cmake-3.15.0-rc1.tar.gz
(2)配置
[root@mysql80 software]# cd cmake-3.15.0-rc1/[root@mysql80 cmake-3.15.0-rc1]# ./configure --prefix=/usr/local/cmake-3.15.0
完成配置,提示如下:
-----------------------------------------------------------------------------------------------------
-- Configuring done
-- Generating done
-- Build files have been written to: /software/cmake-3.15.0-rc1
---------------------------------------------
CMake has bootstrapped. Now run gmake.
-------------------------------------------------------------------------------------------------------
(3)编译
make
(4)安装
make install
(5)校验
[root@mysql80 bin]# type cmakecmake is /usr/local/bin/cmake[root@mysql80 bin]# cmake --versioncmake version 3.15.0-rc1CMake suite maintained and supported by Kitware (kitware.com/cmake).
二.安装gcc-5.3.0
编译安装gcc-5.3.0, 需要注意两点:
(1)gcc本身是编译工具,那编译gcc的工具是什么?所以需要事先通过yum或rpm安装好之前版本的gcc。
yum install gcc gcc-c++ -y
(2)相关依赖包:GMP4.3.2 MPFR2.4.2 MPC0.8.1 ,需要依次事先安装好。
gmp http://ftp.gnu.org/gnu/gmp/
mpfr http://ftp.gnu.org/gnu/mpfr/
mpc http://ftp.gnu.org/gnu/mpc/
1. 安装GMP4.3.2
[root@mysql80 software]# mkdir /usr/local/gmp-4.3.2[root@mysql80 software]# cd /software[root@mysql80 software]# ls -l | grep gmp-rw-r--r--. 1 root root 1897483 Jun 10 09:37 gmp-4.3.2.tar.bz2[root@mysql80 software]# tar -jxvf gmp-4.3.2.tar.bz2 [root@mysql80 software]# cd gmp-4.3.2/[root@mysql80 gmp-4.3.2]# ./configure --prefix=/usr/local/gmp-4.3.2[root@mysql80 gmp-4.3.2]# make[root@mysql80 gmp-4.3.2]# make install
2. 安装MPFR2.4.2
[root@mysql80 software]# mkdir /usr/local/mpfr-2.4.2[root@mysql80 software]# cd /software[root@mysql80 software]# ls -l | grep mpfr-rw-r--r--. 1 root root 1077886 Jun 10 09:38 mpfr-2.4.2.tar.bz2[root@mysql80 software]# tar -jxvf mpfr-2.4.2.tar.bz2 [root@mysql80 software]# cd mpfr-2.4.2/[root@mysql80 mpfr-2.4.2]# ./configure --prefix=/usr/local/mpfr-2.4.2 --with-gmp=/usr/local/gmp-4.3.2[root@mysql80 gmp-4.3.2]# make[root@mysql80 gmp-4.3.2]# make install
3. 安装MPC0.8.1
[root@mysql80 software]# mkdir /usr/local/mpc-0.8.1[root@mysql80 software]# cd /software[root@mysql80 software]# ls -l | grep mpc-0.8.1.tar.gz -rw-r--r--. 1 root root 544950 Jun 10 09:38 mpc-0.8.1.tar.gz[root@mysql80 software]# tar -zxvf mpc-0.8.1.tar.gz [root@mysql80 software]# cd mpc-0.8.1[root@mysql80 mpc-0.8.1]# ./configure --prefix=/usr/local/mpc-0.8.1 --with-gmp=/usr/local/gmp-4.3.2 --with-mpfr=/usr/local/mpfr-2.4.2[root@mysql80 gmp-4.3.2]# make[root@mysql80 gmp-4.3.2]# make install
----------------------------------------------------------------------------------------------------------------------
4. 修改环境变量
vim etc/profile
添加如下行:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-4.3.2/lib:/usr/local/mpfr-2.4.2/lib:/usr/local/gcc-5.3.0/lib:/usr/local/gcc-5.3.0/lib64
使之生效:
source etc/profile
5. 安装GCC5.3.0
[root@mysql80 software]# mkdir /usr/local/gcc-5.3.0[root@mysql80 software]# cd /software[root@mysql80 software]# ls -l gcc-5.3.0.tar.gz -rw-r--r--. 1 root root 123036849 Jun 10 09:17 gcc-5.3.0.tar.gz[root@mysql80 software]# tar -zxvf gcc-5.3.0.tar.gz [root@mysql80 software]# cd gcc-5.3.0/[root@mysql80 gcc-5.3.0]# ./configure --prefix=/usr/local/gcc-5.3.0 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local/gmp-4.3.2 --with-mpfr=/usr/local/mpfr-2.4.2 --with-mpc=/usr/local/mpc-0.8.1[root@mysql80 gmp-4.3.2]# make -j4[root@mysql80 gmp-4.3.2]# make install
6. 创建软连接
cd /usr/bin rm gcc rm g++ ln -s /usr/local/gcc-5.3.0/bin/g++ g++ ln -s /usr/local/gcc-5.3.0/bin/gcc gcc
7.校验
[root@mysql80 bin]# gcc --versiongcc (GCC) 5.3.0Copyright (C) 2015 Free Software Foundation, Inc.This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE[root@mysql80 bin]# g++ --versiong++ (GCC) 5.3.0Copyright (C) 2015 Free Software Foundation, Inc.This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341