当前位置:网站首页>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 .
边栏推荐
- The JVM outputs GC logs, causing the JVM to get stuck. I am stupid
- Notes on writing questions in C language -- table tennis competition
- View touch analysis
- 设计人员拿到的工程坐标系等高线CAD图如何加载进图新地球
- Kubernetes的pod调度
- 刷题笔记(十九)--二叉树:二叉搜索树的修改与构造
- ETL过程中数据精度不准确问题
- 小程序:uniapp解决 vendor.js 体积过大的问题
- R language GLM function logistic regression model, using epidisplay package logistic The display function obtains the summary statistical information of the model (initial and adjusted odds ratio and
- 打新债注册开户安全吗,有没有什么风险?
猜你喜欢
随机推荐
Notes on writing questions in C language -- table tennis competition
Is it safe to open an online stock account? Somebody give me an answer
详解C语言编程题:任意三条边能否构成三角形,输出该三角形面积并判断其类型
The JVM outputs GC logs, causing the JVM to get stuck. I am stupid
使用 Abp.Zero 搭建第三方登录模块(一):原理篇
One copy ten, CVPR oral was accused of plagiarizing a lot, and it was exposed on the last day of the conference!
Cache page keepalive use in Vue
使用RestCloud ETL Shell组件实现定时调度DataX离线任务
Pytorch深度学习代码技巧
R language uses ggplot2 to visualize the results of Poisson regression model and count results under different parameter combinations
人力资源导出数据 excel VBA
Deployment of kubernetes' controller
关于 selenium.common.exceptions.WebDriverException: Message: An unknown server-side error 解决方案(已解决)
房东拿租金去还房贷是天经地义的嘛
Document 1
功能:crypto-js加密解密
Kubernetes的pod调度
R语言使用glm函数构建泊松对数线性回归模型处理三维列联表数据构建饱和模型、使用step函数基于AIC指标实现逐步回归筛选最佳模型、使用summary函数查看简单模型的汇总统计信息
feil_uVission4左侧工目录消失
Execution of commands in the cluster
![[cloud native] codeless IVX editor programmable by](/img/10/7c56e46df69be6be522a477b00ec05.png)







