GUN Compiler Collection GCC is referred to, in addition to the compiler, it also contains other tools, it can easy to source code written in high-level language used by humans to build into binary code a computer can directly execute. GCC is the most commonly used Linux platform compiler, it is the de facto standard Linux platform compiler. Meanwhile, in the field of embedded development on Linux platform, GCC is using the most common type of compiler. The reason why the GCC is widely used, because it can support a variety of different target architectures. For example, both support the development of the host (for a simple platform is to say the compiler, it is compiled on the platform), also supports cross compiler (i.e., A on the platform is a compiled program for use in platform B). Currently, GCC supports architecture more than forty kinds, common with X86 series, Arm, PowerPC and so on. Meanwhile, GCC can run on different operating systems, such as Linux, Solaris, Windows and so on.
In addition to talking about other than the above, GCC addition to supporting C language, also supports a variety of other languages, such as C ++, Ada, Java, Objective-C, FORTRAN, Pascal, go and so on.
Basically when compiling many applications need to install gcc, commonly used version is not very high so quickly through the installation command:
yum install -y gcc-c++
However, some applications require a higher version of gcc compile time, this time basically can only compile the installation, and installation is very troublesome gcc compiler, the compiler needs to rely on a few components to specify the version of the installation is successful, to facilitate the installation of a specially prepared installation shell script, the script unattended installation, of course, the installation process is a bit long to compile the script temporarily only supports CentOS system (system version 5 to 7 has been tested) to install under (other systems need to be adjusted quickly command yum install components and the corresponding installation package name)
! # / bin / bash # official website https://gcc.gnu.org/ # # Download (mirror) # https://gcc.gnu.org/mirrors.html # # depend Description # https: // gcc. gnu.org/install/prerequisites.html # # command parameters # $ 1 specify the installation version, if you do not pass then get the latest version, the latest version is new new # #GCC version number the GCC_VERSION = $ 1 # GCC installation base directory INSTALL_BASE = " / usr / local / GCC / " # necessary libraries base directory INSTALL_PACKAGE_BASE =" / usr / local / " # GCC compiler arranged GCC_CONFIGURE_WITH = '' # mirror address MIRRORS_URL =" http://mirror.linux-ia64.org/gnu / gcc " IF [the -z $ 1] || [[$ 1 ==" new new "]]; the then echo"! gcc version IS empty " echo" get the latest stable version ..."; GCC_VERSION=`curl $MIRRORS_URL/releases/ 2>&1| grep -P 'gcc-\d+\.\d+\.\d+' -o|tail -n 1|grep -P '\d+\.\d+\.\d+' -o` if [ -z "$GCC_VERSION" ];then echo "获取版失败!"; exit fi if [ -z $1 ]; then echo $GCC_VERSION exit fi fi if [ -e "$INSTALL_BASE$GCC_VERSION/bin/gcc" ];then echo "gcc-$GCC_VERSION already install!" exit fi OLD_PATH=`pwd` if [[ "$0" =~ '/' ]]; then cd "`echo "$0" | grep -P '(/?[^/]+/)+' -o`" CURRENT_PATH=`pwd` cd $OLD_PATH else CURRENT_PATH=$OLD_PATH fi if [ ! -d "gcc" ];then mkdir gcc fi cd gcc if [ ! -e "gcc-$GCC_VERSION.tar.gz" ]; then #download php echo "download gcc-$GCC_VERSION.tar.gz"; wget $MIRRORS_URL/releases/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.gz 2>&1 fi if [ ! -d "gcc-$GCC_VERSION" ]; then #decompression echo "decompression gcc-$GCC_VERSION.tar.gz"; tar -zxf gcc-$GCC_VERSION.tar.gz fi if [ ! -d "gcc-$GCC_VERSION" ]; then echo "gcc-$GCC_VERSION dir is not exists" exit fi echo "install dependence" # configuration time is not likely to cause death cycle synchronization -y install gcc-c yum ++ bzip2 ntpdate M4 ntpdate -u ntp.api.bz # while 循环使用的是管道,会开启子进程,无法修改外部的变量 PACKAGE_LISTS=`cat gcc-$GCC_VERSION/contrib/download_prerequisites| grep -P '\-\d+\.\d+(\.\d+)?\.tar'` for LINE in `echo -e $PACKAGE_LISTS` do PACKAGE_VERSION_FILE=`echo $LINE|grep -P '\w+\-\d+\.\d+(\.\d+)?\.tar\.(bz2|gz)' -o` PACKAGE=`echo $PACKAGE_VERSION_FILE|grep -P '^\w+' -o` PACKAGE_VERSION_DIR=`echo $PACKAGE_VERSION_FILE|grep -P '\w+\-\d+\.\d+(\.\d+)?' -o` PACKAGE_VERSION=`echo $PACKAGE_VERSION_DIR|grep -P '\d+\.\d+(\.\d+)?' -o` PACKAGE_CONFIGURE_WITH=$GCC_CONFIGURE_WITH GCC_CONFIGURE_WITH="$PACKAGE_CONFIGURE_WITH --with-$PACKAGE=$INSTALL_PACKAGE_BASE$PACKAGE/$PACKAGE_VERSION" echo "install $PACKAGE_VERSION_DIR" if [ -d "$INSTALL_PACKAGE_BASE$PACKAGE/$PACKAGE_VERSION" ]; then echo "$PACKAGE_VERSION_DIR already install"; continue; fi if [ ! -e "$PACKAGE_VERSION_FILE" ]; then #download package echo "download $PACKAGE_VERSION_FILE"; wget $MIRRORS_URL/infrastructure/$PACKAGE_VERSION_FILE 2>&1 fi if [ ! -d "$PACKAGE_VERSION_DIR" ]; then #decompression echo "decompression $PACKAGE_VERSION_FILE"; if [ -n "`echo $PACKAGE_VERSION_FILE|grep -P '\.gz$'`" ];then tar -zxf $PACKAGE_VERSION_FILE else tar -xf $PACKAGE_VERSION_FILE fi fi if [ ! -d "$PACKAGE_VERSION_DIR" ]; then echo "$PACKAGE_VERSION_DIR dir is not exists" exit fi cd $PACKAGE_VERSION_DIR if [[ "$PACKAGE" == "isl" ]];then PACKAGE_CONFIGURE_WITH=' --with-gmp-prefix='`echo $PACKAGE_CONFIGURE_WITH|grep -P "[^=]+gmp/\d+\.\d+\.\d+" -o` fi echo "./configure --prefix=$INSTALL_PACKAGE_BASE$PACKAGE/$PACKAGE_VERSION$PACKAGE_CONFIGURE_WITH" ./configure --prefix=$INSTALL_PACKAGE_BASE$PACKAGE/$PACKAGE_VERSION$PACKAGE_CONFIGURE_WITH 2>&1 make 2>&1 make install 2>&1 do for `PY_FILE in the Find $ INSTALL_PACKAGE_BASE $ PACKAGE / $ package_version / lib / -name" * .py "` if [ ! -d "$INSTALL_PACKAGE_BASE$PACKAGE/$PACKAGE_VERSION" ] || [ -z "`ls $INSTALL_PACKAGE_BASE$PACKAGE/$PACKAGE_VERSION`" ];then echo "! $ Package- $ package_version install Fail" Exit fi IF [[ "$ PACKAGE" == "ISL"]]; the then echo "mv lib / * py File." # Clear py files, which will affect the share of dynamic link libraries ldconfig command fails IF [-n "$ PY_FILE"] && [-e "$ PY_FILE"]; the then echo "mv $ PY_FILE $ INSTALL_PACKAGE_BASE $ PACKAGE / $ package_version" mv $ PY_FILE $ INSTALL_PACKAGE_BASE $ PACKAGE / $ package_version fi DONE fi # shared dynamic link library, load the configuration if [-d "$ INSTALL_PACKAGE_BASE $ PACKAGE / $ pACKAGE_VERSION / lib"] && [-z "` cat /etc/ld.so.conf|grep "$INSTALL_PACKAGE_BASE$PACKAGE/$PACKAGE_VERSION"`" ];then echo "$INSTALL_PACKAGE_BASE$PACKAGE/$PACKAGE_VERSION/lib" >> /etc/ld.so.conf ldconfig fi cd ../ done cd gcc-$GCC_VERSION echo "install gcc" make clean 2>&1 # 64位系统需要禁用multilib if [ -n "`uname -a|grep -P 'el\d+\.x\d+_\d+' -o|grep x86_64 -o`" ]; then GCC_CONFIGURE_WITH=$GCC_CONFIGURE_WITH' --disable-multilib' fi # 新版需要下载配置文件 if [ ! -e "./configure" ] && [ -e "./contrib/download_prerequisites" ];then ./contrib/download_prerequisites mkdir gcc-make-tmp cd gcc-make-tmp echo "../configure --prefix=$INSTALL_BASE$GCC_VERSION$GCC_CONFIGURE_WITH" ../configure --prefix=$INSTALL_BASE$GCC_VERSION$GCC_CONFIGURE_WITH 2>&1 else echo "./configure --prefix=$INSTALL_BASE$GCC_VERSION$GCC_CONFIGURE_WITH" ./configure --prefix=$INSTALL_BASE$GCC_VERSION$GCC_CONFIGURE_WITH 2>&1 fi HTREAD_NUM=`lscpu |grep Thread|grep -P '\d+$' -o` make -j $HTREAD_NUM 2>&1 make install 2>&1 # check install status if [ ! -d "$INSTALL_BASE$GCC_VERSION" ] || [ -z "`ls $INSTALL_BASE$GCC_VERSION`" ]; then echo "[error] install the GCC-$ GCC_VERSION Fail!"; the else echo "$ GCC_VERSION the install_base $ / lib64" >> /etc/ld.so.conf echo. "lib64 mv / * py File" # Clear py file, these file sharing will affect the dynamic link library ldconfig command execution failed for $ PY_FILE in the install_base $ GCC_VERSION `the Find / lib64 / -name" * .py "` do IF [-n "$ PY_FILE"] && [-e "$ PY_FILE"] ; the then echo "Music Videos PY_FILE $ $ $ GCC_VERSION the install_base" Music Videos PY_FILE $ $ $ GCC_VERSION the install_base Fi DONE the ldconfig echo 'Export the PATH the PATH = $:' "$ $ GCC_VERSION the install_base / bin" >> /etc/profile source /etc/profile yum remove -y gcc-c++ echo "install gcc-$GCC_VERSION success!"; fi
Instructions:
In the root account, create a shell script file a .sh suffix, such as: gcc-install.sh and save the installation code is written above.
The installation command
bash gcc-install.sh new
If the system relies too small lead to an unsuccessful installation, you need to increase the corresponding dependencies (here only as an example to test the system dependencies that may be installed is not very adequate), you can go to the installation directory configuration changes in the installation script, the installation will succeed Tip a successful installation copy.