在CentOS/Debian/Ubuntu上编译安装最新版 GCC 8 , cmake 3 和ninja

CentOS不像Debian/Ubuntu,不能直接从官方库中安装最新版的gcc/g++,只能源码编译安装。

gcc下载地址:Index of /gnu/gcc
我选择了最新版本 gcc-8.3.0,下载tar.gz压缩包,共109M。
然后解压:

tar -xvzf gcc-*.tar.gz

编译前先安装必备的软件:

yum install gmp-devel mpfr-devel libmpc-devel

如果是Debian系统,可以进行如下操作:

-> # cd gcc-8.3.0
-> # ./contrib/download_prerequisites 

如果没安装这几个软件,会报错:

configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.  Source code for these libraries can be found at
their respective hosting sites as well as at
ftp://gcc.gnu.org/pub/gcc/infrastructure/.  See also
http://gcc.gnu.org/install/prerequisites.html for additional info.  If
you obtained GMP, MPFR and/or MPC from a vendor distribution package,
make sure that you have installed both the libraries and the header
files.  They may be located in separate packages.

解决方案:Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+ - Stack Overflow

与其他软件包不同,建议在GCC源目录之外创建另一个构建目录以构建GCC。

mkdir gcc-build 
cd gcc-build 
../gcc-8.3.0/configure --enable-languages=c,c++ --disable-multilib
make -j$(nproc) && make install

我在1核的机器上编译了一下午,在24核的机器上编译了至少20分钟。
然后gcc会被安装在/usr/local目录下。
更新环境变量:

export PATH=/usr/local/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH
gcc --version

现在能跑gcc了,我再更新一下cmake,centos自带的cmake是cmake2.8版本的,现在都3.15了,还不能升级,真的保守。

wget https://cmake.org/files/v3.15/cmake-3.15.4.tar.gz
tar -zxvf  cmake-3.15.4.tar.gz
cd cmake-3.15.4
chmod +x bootstrap
./bootstrap
make 
sudo make install

/usr/local/bin/cmake --version

删除原来的cmake:

yum remove cmake -y
sudo ln -s /usr/local/bin/cmake /usr/bin/
cmake --version

后记:
我在./bootstrap这步的时候报错:

In file included from /root/clickhouse/ft_local/cmake-3.14.5/Source/cmExportFileGenerator.h:11,
                 from /root/clickhouse/ft_local/cmake-3.14.5/Source/cmExportTryCompileFileGenerator.h:8,
                 from /root/clickhouse/ft_local/cmake-3.14.5/Source/cmCoreTryCompile.cxx:13:
/root/clickhouse/ft_local/cmake-3.14.5/Bootstrap.cmk/cmVersionConfig.h:4:23: warning: missing terminating " character
 #define CMake_VERSION "3 .14 .5 "
                       ^
/root/clickhouse/ft_local/cmake-3.14.5/Bootstrap.cmk/cmVersionConfig.h:7:1: warning: missing terminating " character
/root/clickhouse/ft_local/cmake-3.14.5/Bootstrap.cmk/cmVersionConfig.h:7:1: error: missing terminating " character
/root/clickhouse/ft_local/cmake-3.14.5/Bootstrap.cmk/cmVersionConfig.h:5:1: error: expected unqualified-id before numeric constant
gmake: *** [cmCoreTryCompile.o] Error 1
---------------------------------------------
Error when bootstrapping CMake:
Problem while running gmake
---------------------------------------------
Log of errors: /root/clickhouse/ft_local/cmake-3.14.5/Bootstrap.cmk/cmake_bootstrap.log
---------------------------------------------

原因是我下载了Windows的zip包,而不是Linux的tar.gz包


然后安装ninja:
直接下载编译好的二进制文件:Releases · ninja-build/ninja
解压,运行:

unzip ninja-linux.zip
cp ninja /usr/bin/
ninja --version
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页