這么多年來跑程序,最惱火的是軟件安裝不上,又苦于root權限限制鄙人的發揮(相信你也一樣)。而,導致各類軟件安裝不成功,多半由于gcc及各種相關lib和依賴的問題。基于此,某搜集資料,自行配置GCC,終于多次(重復是檢驗真理的標準)成功“搞定”,故,分享命令于此,愿你也能肆意操控gcc,任意“盤”各種gcc依賴相關之軟件些!
(PS:切莫貪心/新,安裝最新GCC版本是不明智的選擇喲!!!自己掂量思考利弊。話不多說,這里以安裝配置gcc-7.3.0為例,代碼附上:)
## config and install gmp-6.1.0
# download into /lustre/gene/software
tar -xvf gmp-6.1.0.tar.bz2
cd gmp-6.1.0
mkdir /lustre/gene/local/gmp-6.1.0
./configure --prefix=/lustre/gene/local/gmp-6.1.0
make && make install
## config and install mpfr-3.1.4.tar.bz2
# download into /lustre/gene/software
tar -xvf? mpfr-3.1.4.tar.bz2
cd mpfr-3.1.4/
mkdir /lustre/gene/local/mpfr-3.1.4
./configure --prefix=/lustre/gene/local/mpfr-3.1.4 --with-gmp=/lustre/gene/local/gmp-6.1.0/
make && make install
#為了方便,添加PATH
export LD_LIBRARY_PATH=/lustre/gene/local/gmp-6.1.0/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=/lustre/gene/local/gmp-6.1.0/include:$C_INCLUDE_PATH
export LD_LIBRARY_PATH=/lustre/gene/local/mpfr-3.1.4/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=/lustre/gene/local/mpfr-3.1.4/include:$C_INCLUDE_PATH
## config and install mpc-1.0.3 (其安裝依賴gmp和mpfr,這也是前面添加path的原因)
# download into /lustre/gene/software
tar -xvf mpc-1.0.3.tar.gz
cd mpc-1.0.3/
mkdir /lustre/gene/local/mpc-1.0.3/
./configure --prefix=/lustre/gene/local/mpc-1.0.3/ --with-gmp=/lustre/gene/local/gmp-6.1.0/ --with-mpfr=/lustre/gene/local/mpfr-3.1.4
make && make install
export LD_LIBRARY_PATH=/lustre/gene/local/mpc-1.0.3/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=/lustre/gene/local/mpc-1.0.3/include:$C_INCLUDE_PATH
'''
如果不希望看到如下configure的錯誤,一定要添加--with-gmp, --with-mpfr and/or --with-mpc參數及相關路徑
configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ 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.
'''
mkdir /lustre/gene/local/gcc-7.3.0
cd /lustre/gene/local/gcc-7.3.0
/lustre/gene/software/gcc-7.3.0/configure --prefix=/lustre/gene/local/gcc-7.3.0 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/lustre/gene/local/gmp-6.1.0 --with-mpfr=/lustre/gene/local/mpfr-3.1.4 --with-mpc=/lustre/gene/local/mpc-1.0.3
make && make install
(take few hours,去打幾把榮耀吧!!)
# 添加最終環境變量到bash
export LD_LIBRARY_PATH=/lustre/gene/local/gmp-6.1.0/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=/lustre/gene/local/gmp-6.1.0/include:$C_INCLUDE_PATH
export LD_LIBRARY_PATH=/lustre/gene/local/mpfr-3.1.4/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=/lustre/gene/local/mpfr-3.1.4/include:$C_INCLUDE_PATH
export LD_LIBRARY_PATH=/lustre/gene/local/mpc-1.0.3/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=/lustre/gene/local/mpc-1.0.3/include:$C_INCLUDE_PATH
export PATH=/lustre/gene/local/gcc-7.3.0/bin:$PATH
export LD_LIBRARY_PATH=/lustre/gene/local/gcc-7.3.0/lib:/lustre/gene/local/gcc-7.3.0/lib64:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=/lustre/gene/local/gcc-7.3.0/include:$C_INCLUDE_PATH