Showing Posts From
Linux
Centos7 Upgrade GCC
Introduction This guide covers upgrading GCC on Centos7 using source code compilation, so you don't need to switch GCC environments after installation. 1. Switch to root user su yum -y install wget2. Download GCC source The following command will save to /usr/local/ wget http://ftp.gnu.org/gnu/gcc/gcc-4.9.2/gcc-4.9.2.tar.gz3. Extract the archive cd /usr/local/ tar -zxvf gcc-4.9.2.tar.gz4. Download compilation dependencies 4.1 If you have internet access cd gcc-4.9.2 ./contrib/download_prerequisites4.2 If you don't have internet access Download these packages on Windows:ftp://ftp.gnu.org/gnu/gmp/gmp-4.3.2.tar.bz2 http://www.mpfr.org/mpfr-2.4.2/mpfr-2.4.2.tar.bz2 http://www.multiprecision.org/mpc/download/mpc-0.8.1.tar.gzThen extract and move to gcc-4.9.2: tar -xjf gmp-4.3.2.tar.bz2 tar -xjf mpfr-2.4.2.tar.bz2 tar -xzf mpc-0.8.1.tar.gz mv gmp-4.3.2 gcc-4.9.2/gmp mv mpfr-2.4.2 gcc-4.9.2/mpfr mv mpc-0.8.1 gcc-4.9.2/mpc5. Compile and install GCC yum install -y gcc-c++ glibc-static gcc ./configure --prefix=/usr/local/gcc --enable-bootstrap --enable-checking=release --enable-languages=c,c++ --disable-multilib make make installCompilation Parameters--prefix=/usr/local/ Specify installation path --enable-bootstrap Use the first compiled program for second compilation --enable-checking=release Run consistency checks at software release standards --enable-languages=c,c++ Supported high-level languages and runtime libraries --disable-multilib Disable 32-bit code generation on 64-bit systemsConfigure Environment Variables 1. Check current gcc version gcc -v # gcc (GCC) 4.8.5 20120313 (Red Hat 4.8.5-16)2. Create environment variable script vim /etc/profile.d/gcc.sh # Add: export PATH=/usr/local/gcc/bin:$PATH3. Activate environment variables source /etc/profile.d/gcc.sh gcc -v # gcc (GCC) 4.9.2Export Header Files ln -sv /usr/local/gcc/include/ /usr/include/gccExport Library Files vim /etc/ld.so.conf.d/gcc.conf # Add: /usr/local/gcc/lib64 ldconfig -v ldconfig -p |grep gccNotes If your program was previously running on a gcc >= 4.9.2 environment, you can switch using: source /opt/rh/devtoolset-7/enable # or source scl_source enable devtoolset-7
