当前位置:网站首页>One click GCC script installation
One click GCC script installation
2022-06-26 15:09:00 【BOGO】
GCC yes GUN Compiler Collection For short , In addition to the compiler , It also contains other related tools , It can build the source code written in high-level language that is easy for human to use into binary code that can be directly executed by computer .
GCC yes Linux The most commonly used compiler under the platform , It is Linux The de facto standard for platform compilers . meanwhile , stay Linux Embedded development field under the platform ,GCC It is also the most commonly used compiler .GCC It is widely used , Because it can support different target architectures . for example , It supports both host based development ( Simply put, it means compiling programs for a certain platform , Compile on this platform ), Cross compiling is also supported ( That is to say A The program compiled on the platform is for the platform B The use of ). at present ,GCC There are more than forty supported architectures , Common are X86 series 、Arm、PowerPC etc. . meanwhile ,GCC It can also run on different operating systems , Such as Linux、Solaris、Windows etc. .
In addition to the above ,GCC In addition to supporting C Language , Many other languages are also supported , for example C++、Ada、Java、Objective-C、FORTRAN、Pascal、go etc. .
Basically, many applications need to use... When compiling and installing gcc, Generally, the version used is not very high, so you can use the shortcut installation command :
yum install -y gcc-c++But some applications need a higher version when compiling gcc, At this time, you can only compile and install , and gcc Compiling and installing is very troublesome , Several dependent components of the specified version are required to compile and install successfully , For the convenience of installation, an installation shell Script , Unattended installation through scripts , Of course, the installation and compilation process is still a bit long , The script only supports CentOS System ( System version 5~7 Have you tested ) To install ( Other systems need to adjust the command of quickly installing components yum And the corresponding installation package name )
#!/bin/bash
# Official website https://gcc.gnu.org/
#
# Download address ( Mirror image )
# https://gcc.gnu.org/mirrors.html
#
# Dependency statement
# https://gcc.gnu.org/install/prerequisites.html
#
# Command parameter
# $1 Specify the installation version , If not, get the latest version number , by new Install the latest version when
#
#GCC version number
GCC_VERSION=$1
# GCC Installation base directory
INSTALL_BASE="/usr/local/gcc/"
# Required library base directory
INSTALL_PACKAGE_BASE="/usr/local/"
# gcc Compile configuration
GCC_CONFIGURE_WITH=''
# Mirror address
MIRRORS_URL="http://mirror.linux-ia64.org/gnu/gcc"
if [ -z $1 ] || [[ $1 == "new" ]]; then
echo "gcc version is empty!"
echo " Get the latest stable version number ...";
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 " Failed to get version !";
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"
yum install -y gcc-c++ bzip2 ntpdate m4
# Time out of sync is easy to cause configuration dead cycle
ntpdate -u ntp.api.bz
# while What is recycled is pipes , Will start the subprocess , Cannot modify external variables
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
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" ]];then
echo "mv lib/*.py file"
# eliminate py file , These files will affect the shared dynamic link library ldconfig Command execution failed
for PY_FILE in `find $INSTALL_PACKAGE_BASE$PACKAGE/$PACKAGE_VERSION/lib/ -name "*.py"`
do
if [ -n "$PY_FILE" ] && [ -e "$PY_FILE" ];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 Bit system needs to be disabled 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
# The new version needs to download the configuration file
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 gcc-$GCC_VERSION fail!";
else
echo "$INSTALL_BASE$GCC_VERSION/lib64" >> /etc/ld.so.conf
echo "mv lib64/*.py file"
# eliminate py file , These files will affect the shared dynamic link library ldconfig Command execution failed
for PY_FILE in `find $INSTALL_BASE$GCC_VERSION/lib64/ -name "*.py"`
do
if [ -n "$PY_FILE" ] && [ -e "$PY_FILE" ];then
echo "mv $PY_FILE $INSTALL_BASE$GCC_VERSION"
mv $PY_FILE $INSTALL_BASE$GCC_VERSION
fi
done
ldconfig
echo 'export PATH=$PATH:'"$INSTALL_BASE$GCC_VERSION/bin" >> /etc/profile
source /etc/profile
yum remove -y gcc-c++
echo "install gcc-$GCC_VERSION success!";
fiUsage method :
stay root Under Account No , Create a .sh Suffix shell Script files , such as :gcc-install.sh Write and save the above installation code .
Execute the installation command
bash gcc-install.sh newIf the installation is unsuccessful due to too few system dependencies , You need to add the corresponding dependent packages ( Here, we only take the test system as an example. The dependent packages may not be installed enough ), The installation directory can be configured and modified in the installation script , After the installation is successful, you will be prompted that the installation is successful .
边栏推荐
- 网上找客户经理办理股票开户安全吗??
- Redis集群消息
- TCP/IP协议竟然有这么多漏洞?
- TCP congestion control details | 1 summary
- kubernetes的Controller之deployment
- Cache page keepalive use in Vue
- Unity C# 网络学习(十)——UnityWebRequest(一)
- [async/await] - the final solution of asynchronous programming
- R语言epiDisplay包的tableStack函数制作统计汇总表格(分组的描述性统计、假设检验等)、不设置by参数计算基础描述性统计信息、指定对于大多数样本负相关的变量进行反序
- Unity 利用Skybox Panoramic着色器制作全景图预览有条缝隙问题解决办法
猜你喜欢
MySQL数据库基本SQL语句教程之高级操作

The JVM outputs GC logs, causing the JVM to get stuck. I am stupid

Bank of Beijing x Huawei: network intelligent operation and maintenance tamps the base of digital transformation service

Program analysis and Optimization - 8 register allocation

About selenium common. exceptions. Webdriverexception: message: an unknown server side error solution (resolved)

The heavyweight white paper was released. Huawei continues to lead the new model of smart park construction in the future

Minister of investment of Indonesia: Hon Hai is considering establishing electric bus system and urban Internet of things in its new capital

小程序:uniapp解决 vendor.js 体积过大的问题

15 BS object Node name Node name String get nested node content

vsomeip3 双机通信文件配置
随机推荐
Unity unitywebrequest download package
ETL过程中数据精度不准确问题
TCP/IP协议竟然有这么多漏洞?
NVIDIA SMI error
Sikuli 基于图形识别的自动化测试技术
Kubernetes的pod调度
Principle of TCP reset attack
Practical website recommendations worth collecting for College Students
C语言刷题随记 —— 乒乓球比赛
Smoothing data using convolution
SAP 销售数据 实际发货数据导出 销量
【雲原生】 ”人人皆可“ 編程的無代碼 iVX 編輯器
clustermeet
Unity C # e-learning (10) -- unitywebrequest (2)
Redis cluster messages
Lexin AWS IOT expresslink module achieves universal availability
feil_uVission4左侧工目录消失
BLE抓包调试信息分析
Unity C# 网络学习(十)——UnityWebRequest(二)
Go变量的声明与赋值