C语言源代码编译安装过程

只谈情不闲聊 提交于 2020-01-17 04:57:21

C语言源代码编译安装过程

利用编译工具,通常只需要三个大的步骤
./confifigure
(1) 通过选项传递参数,指定安装路径、启用特性等;执行时会参考用户的指定以及Makefifile.in文
件生成Makefifile
(2) 检查依赖到的外部环境,如依赖的软件包
make 根据Makefifile文件,构建应用程序
make install 复制文件到相应路径
注意:安装前可以通过查看README,INSTALL获取帮助

编译安装准备开发工具:

make, gcc
安装包建议保存在/usr/local/src
解包 tar -xvf
prefix = /apps/tree 软件建议安装在这个文件夹

编译安装

第一步:运行 confifigure 脚本
选项主要功能:
可以指定安装位置
指定启用的特性

选项分类:

安装路径设定:
–prefifix=/PATH:指定默认安装位置,默认为/usr/local/

./configure --prefix=/apps/matrix
–sysconfdir=/PATH:配置文件安装位置
System types:支持交叉编译
软件特性和相关指定:
Optional Features: 可选特性
–disable-FEATURE
–enable-FEATURE[=ARG]
Optional Packages: 可选包
–with-PACKAGE[=ARG] 依赖包
–without-PACKAGE 禁用依赖关系
注意:通常被编译操作依赖的程序包,需要安装此程序包的“开发”组件,其包名一般类似于name-devel-VERSION
第二步:make
第三步:make install

安装后的配置

  1. 二进制程序目录导入至PATH环境变量中
    编辑文件/etc/profifile.d/NAME.sh

  2. 相关用户及文件
    有些开源软件编译完成后,还需要创建相关的用户及文件

  3. 导入帮助手册
    编辑/etc/man.confifig|man_db.conf文件,添加一个MANPATH

例:centos8 编译安装httpd-2.4.41

[root@centos8|2|~]#dnf install -y make gcc
[root@centos8|9|src]#pwd
/usr/local/src
[root@centos8 src]#wget http://mirror.bit.edu.cn/apache//httpd/httpd- 2.4.41.tar.bz2
[root@centos8|10|src]#tar xf httpd-2.4.25.tar.bz2 
[root@centos8|11|src]#ls
cmatrix-1.2a  cmatrix-1.2a.tar.gz  httpd-2.4.25  httpd-2.4.25.tar.bz2
root@centos8|12|src]#cd httpd-2.4.25/
[root@centos8|13|httpd-2.4.25]#ls
ABOUT_APACHE     buildconf       httpd.dsp       libhttpd.mak   README.cmake
acinclude.m4     CHANGES         httpd.mak       LICENSE        README.platforms
Apache-apr2.dsw  CMakeLists.txt  httpd.spec      Makefile.in    ROADMAP
Apache.dsw       config.layout   include         Makefile.win   server
apache_probes.d  configure       INSTALL         modules        srclib
ap.d             configure.in    InstallBin.dsp  NOTICE         support
build            docs            LAYOUT          NWGNUmakefile  test
BuildAll.dsp     emacs-style     libhttpd.dep    os             VERSIONING
BuildBin.dsp     httpd.dep       libhttpd.dsp    README
[root@centos8|14|httpd-2.4.25]#./configure \
> --prefix=/apps/httpd24\
> sysconfdir=/etc/httpd24\
> --enable-ss1\
> --enable-so
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... no
configure: error: APR not found.  Please read the documentation.
[root@centos8 httpd-2.4.41]#dnf list available "*apr*" 
[root@centos8 httpd-2.4.41]#dnf install apr-devel -y
[root@centos8|24|httpd-2.4.25]#yum install -y apr-util-devel.x86_64
[root@centos8|28|httpd-2.4.25]#yum install -y pcre-devel.x86_64
[root@centos8|29|httpd-2.4.25]#./configure --prefix=/apps/httpd24 --sysconfdir=/etc/httpd24 --enable-ss1 --enable-so
[root@centos8 httpd-2.4.41]#make -j 4 && make install
[root@centos8 ~]#echo 'PATH=/apps/httpd24/bin:$PATH' > /etc/profile.d/httpd24.sh [root@centos8 ~]#. /etc/profile.d/httpd24.sh 
 [root@centos8 ~]#apachectl start 
 [root@centos8 ~]#vim /apps/httpd24/htdocs/index.html 
 [root@centos8 ~]#cat /apps/httpd24/htdocs/index.html 
[root@centos8 ~]#useradd -r -s /sbin/nologin apache 
[root@centos8 ~]#vim /etc/httpd24/httpd.conf 
user apache group apache 
[root@centos8 ~]#apachectl -k stop
 [root@centos8 ~]#apachectl start 
  [root@centos8 ~]#ps aux 查看

一键安装httpd脚本

#本地自制安装包
#URL=http://10.0.0.113/tar/
#最新版本地址
URL=http://mirror.bit.edu.cn/apache//httpd/
#旧版本地址
#URL=http://archive.apache.org/dist/httpd/
VERSION=`sed -nr 's@^VERSION_ID="([0-9])"$@\1@p' /etc/os-release `
if [ $VERSION -eq 7 ] ; then
   FILE=httpd-2.4.38.tar.bz2
else 
    FILE=httpd-2.4.41.tar.bz2
fi
ZIPTYPE=`echo $FILE | sed -nr 's@.*\.([^\.])@\1@p'`
DIR=`echo $FILE | sed -nr 's@^(.*[0-9]+)\.[[:alpha:]]+.*$@\1@p'`
INSTALLDIR=/apps/http24
SUBDIR=`basename $INSTALLDIR`
[ -d $INSTALLDIR ] &&  { echo "软件已经安装,退出" ; exit ;  } 
yum -y install  gcc wget make apr-devel  pcre-devel  openssl-devel apr-util-devel redhat-rpm-config
mkdir -pv /etc/local/src &>> /dev/null
cd /etc/local/src
wget $URL$FILE
case $ZIPTYPE in
bz2|gz|xz)
    tar xf $FILE
    ;;
zip)
    unzip $FILE
    ;;
*)
    echo "不支持的压缩类型"
    exit 10
esac
cd $DIR
./configure  \
--prefix=$INSTALLDIR  \
--sysconfdir=/etc/$SUBDIR  \
--enable-ssl  \
--enable-so
make  && make install
\rm -rf  /etc/local/src/$DIR*
echo 'PATH='''${INSTALLDIR}'''/bin:$PATH' > /etc/profile.d/$SUBDIR.sh
source /etc/profile.d/$SUBDIR.sh
useradd -r -s /sbin/nologin apache
sed -ri 's@(^.*<h1>).*(</h1>.*$)@\1 Hello Word!! \2@' $INSTALLDIR/htdocs/index.html
sed -i -e 's@^User .*@User apache@' -e 's@^Group .*@Group apache@' /etc/$SUBDIR/httpd.conf 
apachectl start
#本地自制安装包
#URL=http://10.0.0.113/tar/
#最新版本地址
URL=http://mirror.bit.edu.cn/apache//httpd/
#旧版本地址
#URL=http://archive.apache.org/dist/httpd/
VERSION=`sed -nr 's@^VERSION_ID="([0-9])"$@\1@p' /etc/os-release `
if [ $VERSION -eq 7 ] ; then
   FILE=httpd-2.4.38.tar.bz2
else 
    FILE=httpd-2.4.41.tar.bz2
fi
ZIPTYPE=`echo $FILE | sed -nr 's@.*\.([^\.])@\1@p'`
DIR=`echo $FILE | sed -nr 's@^(.*[0-9]+)\.[[:alpha:]]+.*$@\1@p'`
INSTALLDIR=/apps/http24
SUBDIR=`basename $INSTALLDIR`
[ -d $INSTALLDIR ] &&  { echo "软件已经安装,退出" ; exit ;  } 
yum -y install  gcc wget make apr-devel  pcre-devel  openssl-devel apr-util-devel redhat-rpm-config
mkdir -pv /etc/local/src &>> /dev/null
cd /etc/local/src
wget $URL$FILE
case $ZIPTYPE in
bz2|gz|xz)
    tar xf $FILE
    ;;
zip)
    unzip $FILE
    ;;
*)
    echo "不支持的压缩类型"
    exit 10
esac
cd $DIR
./configure  \
--prefix=$INSTALLDIR  \
--sysconfdir=/etc/$SUBDIR  \
--enable-ssl  \
--enable-so
make  && make install
\rm -rf  /etc/local/src/$DIR*
echo 'PATH='''${INSTALLDIR}'''/bin:$PATH' > /etc/profile.d/$SUBDIR.sh
source /etc/profile.d/$SUBDIR.sh
useradd -r -s /sbin/nologin apache
sed -ri 's@(^.*<h1>).*(</h1>.*$)@\1 Hello Word!! \2@' $INSTALLDIR/htdocs/index.html
sed -i -e 's@^User .*@User apache@' -e 's@^Group .*@Group apache@' /etc/$SUBDIR/httpd.conf 
apachectl start
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!