在Linux服务器上安装GCC,Boost和Cmake

GCC的安装

下载gcc-6.3.0

1
2
3
4
cd /panfs/home/zhao/zhangjy/software/src/gcc_src/
wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-6.3.0/gcc-6.3.0.tar.gz
tar zxvf gcc-6.3.0.tar.gz
cd gcc-6.3.0

安装依赖的mpfr, gmp和mpc等依赖工具

1
./contrib/download_prerequisites

在新的目录下编译

1
2
3
mkdir -p /panfs/home/zhao/zhangjy/software/src/gcc_build
cd /panfs/home/zhao/zhangjy/software/src/gcc_build
/panfs/home/zhao/zhangjy/software/src/gcc_src/gcc-6.3.0/configure --prefix=/panfs/home/zhao/zhangjy/software/gcc --disable-multilib

修改环境变量

1
2
echo $LD_LIBRARY_PATH
echo $LIBRARY_PATH

如果输出的$LD_LIBRARY_PATHLIBRARY_PATH是以:结尾,比如:

1
/public/software/intel/composer_xe_2011_sp1.7.256/compiler/lib/intel64:/public/software/intel/composer_xe_2011_sp1.7.256/mkl/lib/intel64:

需要去掉结尾处的:,否则make时候会报错

1
export LIBRARY_PATH=/public/software/intel/composer_xe_2011_sp1.7.256/compiler/lib/intel64:/public/software/intel/composer_xe_2011_sp1.7.256/mkl/lib/intel64

安装GCC

1
2
make -j 10 # make in 10 threads
make install

添加新安装的GCC到环境变量

Note: $LD_LIBRARY_PATH中要加入两个目录

1
2
3
export PATH=/panfs/home/zhao/zhangjy/software/gcc/bin:$PATH
export LD_LIBRARY_PATH=/panfs/home/zhao/zhangjy/software/gcc/lib/gcc/x86_64-pc-linux-gnu/6.3.0:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/panfs/home/zhao/zhangjy/software/gcc/lib64:$LD_LIBRARY_PATH

当安装其他软件时,指定调用新版的GCC

1
2
3
export CC=/panfs/home/zhao/zhangjy/software/gcc/bin/gcc
export CXX=/panfs/home/zhao/zhangjy/software/gcc/bin/g++
cmake $YOUR_PATH -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR

Boost的安装

下载Boost

1
2
3
wget https://nchc.dl.sourceforge.net/project/boost/boost/1.63.0/boost_1_63_0.tar.gz
tar zxvf boost_1_63_0.tar.gz
cd boost_1_63_0

安装Boost

1
sh ./bootstrap.sh

指定boost安装目录和include, lib文件夹的位置

1
./bjam -j 4 --prefix=/panfs/home/zhao/zhangjy/software/boost --includedir=/panfs/home/zhao/zhangjy/software/boost --libdir=/panfs/home/zhao/zhangjy/software/boost install

添加到环境变量

1
2
export PATH=/panfs/home/zhao/zhangjy/software/boost/boost:$PATH
export LD_LIBRARY_PATH=/panfs/home/zhao/zhangjy/software/boost/lib:$LD_LIBRARY_PATH

安装Cmake

下载Cmake

1
2
3
wget https://cmake.org/files/v3.7/cmake-3.7.2.tar.gz --no-check-certificate
tar zxvf cmake-3.7.2.tar.gz
cd cmake-3.7.2

安装Cmake

1
2
./bootstrap --prefix=/panfs/home/zhao/zhangjy/software/cmake
gmake && gmake install

添加到环境变量

1
export PATH=/panfs/home/zhao/zhangjy/software/cmake/bin:$PATH