gcc官网:https://gcc.gnu.org/
1.安装系统默认gcc(有则忽略)
yum install -y gcc gcc-c++ make
2.下载高版本gcc源码包
下载地址:https://ftp.gnu.org/gnu/gcc/
wget https://ftp.gnu.org/gnu/gcc/gcc-7.5.0/gcc-7.5.0.tar.gz
3.源码编译安装
#解压 tar -xvf gcc-7.5.0.tar.gz #下载依赖 cd gcc-7.5.0 ./contrib/download_prerequisites #编译安装 ./configure --prefix=/usr/local/gcc-7.5.0 --enable-threads=posix --disable-multilib --enable-languages=c,c++,fortran make -j16 #cpu核数 make install
4.设置GCC环境变量
#设置变量 export GCC_HOME=/usr/local/gcc-7.5.0 export PATH=${GCC_HOME}/bin:$PATH export LD_LIBRARY_PATH=${GCC_HOME}/lib:${GCC_HOME}/lib64:$LD_LIBRARY_PATH export LIBRARY_PATH=${GCC_HOME}/lib:${GCC_HOME}/lib64:$LIBRARY_PATH export MANPATH=${GCC_HOME}/share/man:$MANPATH export INCLUDE=${GCC_HOME}/include:$INCLUDE #CMAKE编译设置 export CC=gcc CXX=g++ FC=gfortran
小知识:LIBRARY_PATH与LD_LIBRARY_PATH变量区别
LIBRARY_PATH环境变量用于编译,在程序编译期间查找动态链接库时指定查找共享库的路径,例如,指定gcc编译需要用到的动态链接库的目录。
LD_LIBRARY_PATH环境变量用于运行,在程序加载运行期间查找动态链接库时指定除了系统默认路径之外的其他路径。
标签:GCC,gcc,LIBRARY,编译,源码,export,HOME,PATH From: https://www.cnblogs.com/imxusq/p/17894294.html