簡介
GCC
- GCC 的意思也只是 GNU C Compiler 而已序目。經(jīng)過了這么多年的發(fā)展坑律,GCC 已經(jīng)不僅僅能支持 C 語言岩梳;它現(xiàn)在還支持 Ada 語言、C++ 語言晃择、Java 語言冀值、Objective C 語言、Pascal 語言宫屠、COBOL語言列疗,以及支持函數(shù)式編程和邏輯編程的 Mercury 語言,等等浪蹂。而 GCC 也不再單只是 GNU C 語言編譯器的意思了抵栈,而是變成了 GNU Compiler Collection 也即是 GNU 編譯器家族的意思了告材。另一方面,說到 GCC 對于操作系統(tǒng)平臺及硬件平臺支持竭讳,概括起來就是一句話:無所不在
make
- 無論是在Linux還是在UNIX環(huán)境中创葡,make都是一個非常重要的編譯工具浙踢。無論是自己進行項目開發(fā)還是安裝應(yīng)用軟件绢慢,都需要使用make工具。利用make工具洛波,可以將大型的開發(fā)項目分解成為多個更易于管理的模塊胰舆,對于一個包括幾百個源文件的應(yīng)用程序而言,使用make工具和makefile文件就可以清晰地理順各個源文件之間的關(guān)系蹬挤。而且如此多的源文件缚窿,如果每次都要輸入gcc命令進行編譯的話,對程序員來說是很難忍受的焰扳。make工具可以自動完成編譯工作倦零,并且只對程序員在上次編譯后修改過的部分進行編譯。因此吨悍,有效地利用make工具可以大大提高項目開發(fā)的效率
程序包編譯
- 上圖就是編譯的過程
- 程序包編譯安裝:
- Application-VERSION-release.src.rpm --> 安裝后
- 使用 用rpmbuild 命令制作成二進制格式的rpm 包,而后再安裝
- 源代碼--> 預處理--> 編譯--> 匯編--> 鏈接--> 執(zhí)行
- 源代碼組織格式:
- 多文件:文件中的代碼之間,很可能存在跨文件依賴關(guān)系
- C 询微、C++ :make 項目管理器
- configure --> Makefile.in --> makefile
- java: mave
- 下面開始安裝包組里面集成了make和GCC
安裝包組
- 編譯C 源代碼:
- 準備:提供開發(fā)工具及開發(fā)環(huán)境
- 開發(fā)工具:make, gcc等 等
- 開發(fā)環(huán)境:開發(fā)庫株依,頭文件
- glibc :標準庫
- 實現(xiàn):通過“包組”提供開發(fā)組件
- Development Tools
- Server Platform Development
- Development Tools
- Development Tools里面有幾十個,大家主要使用其中的gcc, make等編譯工具
- 首先我們要測試是否配好了yum 源躏仇,可以用
yum list|grep
來測試
[root@localhost ~]# yum list|grep httpd
httpd.x86_64 2.4.6-45.el7.centos bash
httpd-devel.x86_64 2.4.6-45.el7.centos bash
httpd-manual.noarch 2.4.6-45.el7.centos bash
httpd-tools.x86_64 2.4.6-45.el7.centos bash
libmicrohttpd.i686 0.9.33-2.el7 bash
libmicrohttpd.x86_64 0.9.33-2.el7 bash
libmicrohttpd-devel.i686 0.9.33-2.el7 bash
libmicrohttpd-devel.x86_64 0.9.33-2.el7 bash
libmicrohttpd-doc.noarch 0.9.33-2.el7 bash
- yum源配好了以后我們來查找包組可以用
yum grouplist
來查詢包組
[root@localhost ~]# yum grouplist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Available Environment Groups:
Minimal Install
Compute Node
Infrastructure Server
File and Print Server
Basic Web Server
Virtualization Host
Server with GUI
GNOME Desktop
KDE Plasma Workspaces
Development and Creative Workstation
Installed Groups:
Development Tools 《《《《《《《《這里就是我們要安裝的包組
Available Groups:
Compatibility Libraries
Console Internet Tools
Graphical Administration Tools
Legacy UNIX Compatibility
Scientific Support
Security Tools
Smart Card Support
System Administration Tools
System Management
Done
- 那我們來開始安裝
Development Tools
包組恋脚,可以用命令yum install Development Tools
來安裝包組
[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: bash epel
Cleaning up everything
Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]# yum install "Development tools"
Loaded plugins: fastestmirror, langpacks
bash | 4.3 kB 00:00:00
epel | 4.3 kB 00:00:00
(1/6): bash/updateinfo | 807 kB 00:00:00
(2/6): bash/primary_db | 4.7 MB 00:00:04
(3/6): epel/group_gz | 170 kB 00:00:00
(4/6): epel/updateinfo | 807 kB 00:00:00
(5/6): epel/primary_db | 4.7 MB 00:00:04
(6/6): bash/group_gz
- 安裝包組以后開始找到源碼包可以上傳也可以去包里面下載我這里用
httpd-2.4.25.tar.bz2
源碼包做演示 - 首先解壓
httpd-2.4.25.tar.bz2
包,可以用tar -xf
命令來解壓
[root@localhost /]# tar -vxf httpd-2.4.25.tar.bz2
httpd-2.4.25/support/suexec.h
httpd-2.4.25/support/win32/
httpd-2.4.25/support/win32/apache_header.bmp
httpd-2.4.25/support/win32/ApacheMonitor.c
httpd-2.4.25/support/win32/ApacheMonitor.dep
httpd-2.4.25/support/win32/ApacheMonitor.dsp
httpd-2.4.25/support/win32/ApacheMonitor.h
httpd-2.4.25/support/win32/ApacheMonitor.ico
httpd-2.4.25/support/win32/ApacheMonitor.mak
httpd-2.4.25/support/win32/ApacheMonitor.manifest
httpd-2.4.25/support/win32/ApacheMonitor.rc
httpd-2.4.25/support/win32/aprun.ico
- 下面
httpd-2.4.25
就是我們解壓的文件目錄用cd
切換到httpd-2.4.25
目錄里面
[root@localhost /]# ls
bin dev home httpd-2.4.25.tar.bz2 lib64 mnt proc run srv tmp var
boot etc httpd-2.4.25 lib media opt root sbin sys usr
- 我們來看下
httpd-2.4.25
目錄里面有什么焰手,想就是httpd-2.4.25
所有文件
[root@localhost httpd-2.4.25]# ls
ABOUT_APACHE build config.layout httpd.dsp LAYOUT Makefile.win README.cmake test
acinclude.m4 BuildAll.dsp configure httpd.mak libhttpd.dep modules README.platforms VERSIONING
Apache-apr2.dsw BuildBin.dsp configure.in httpd.spec libhttpd.dsp NOTICE ROADMAP
Apache.dsw buildconf docs include libhttpd.mak NWGNUmakefile server
apache_probes.d CHANGES emacs-style INSTALL LICENSE os srclib
ap.d CMakeLists.txt httpd.dep InstallBin.dsp Makefile.in README support
- 下面我們就開始編譯測試安裝了可以用
configure
來測試用--prefix=/PATH:
指定默認安裝位置, 默認為/usr/local/
[root@localhost httpd-2.4.25]# ./configure --prefix=/app
- 編譯開始糟描,編譯過程中可能會遇到很多問題下面請看
[root@localhost httpd-2.4.25]# ./configure --prefix=/app
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.
- 遇到一個錯誤說要APR包,我們可以用
yum search apr
來查包
[root@localhost httpd-2.4.25]# yum search apr
apr-devel.i686 : APR library development kit 《《《《《《《這個就是我們的APR包
apr-devel.x86_64 : APR library development kit
apr-util-devel.i686 : APR utility library development kit
apr-util-devel.x86_64 : APR utility library development kit
apr-util-ldap.x86_64 : APR utility library LDAP support
apr-util-mysql.x86_64 : APR utility library MySQL DBD driver
apr-util-nss.x86_64 : APR utility library NSS crytpo support
apr-util-odbc.x86_64 : APR utility library ODBC DBD driver
apr-util-openssl.x86_64 : APR utility library OpenSSL crytpo support
apr-util-pgsql.x86_64 : APR utility library PostgreSQL DBD driver
apr-util-sqlite.x86_64 : APR utility library SQLite DBD driver
我們只需要安裝包即可用命令
yum install apr-devel
來安裝安裝完畢以后又來編譯測試看他還報錯不
./configure --prefix=/app
又出現(xiàn)了錯誤
error: APR-util not found. Please read the documentation.
[root@localhost httpd-2.4.25]# ./configure --prefix=/app
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... yes
setting CC to "gcc"
setting CPP to "gcc -E"
setting CFLAGS to " -pthread"
setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"
setting LDFLAGS to " "
configure:
configure: Configuring Apache Portable Runtime Utility library...
configure:
checking for APR-util... no
configure: error: APR-util not found. Please read the documentation.
- 我們繼續(xù)找APR-util包一樣的命令
yum search APR-util
[root@localhost httpd-2.4.25]# yum search APR-util
apr-util.i686 : Apache Portable Runtime Utility library
apr-util.x86_64 : Apache Portable Runtime Utility library
apr-util-devel.i686 : APR utility library development kit
apr-util-devel.x86_64 : APR utility library development kit 《我的APR-util包
apr-util-ldap.x86_64 : APR utility library LDAP support
apr-util-mysql.x86_64 : APR utility library MySQL DBD driver
apr-util-nss.x86_64 : APR utility library NSS crytpo support
apr-util-odbc.x86_64 : APR utility library ODBC DBD driver
apr-util-openssl.x86_64 : APR utility library OpenSSL crytpo support
apr-util-pgsql.x86_64 : APR utility library PostgreSQL DBD driver
apr-util-sqlite.x86_64 : APR utility library SQLite DBD driver
- 安裝完畢以后在用
yum search apr
來查包 - 出現(xiàn)
pcre-config
錯誤
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
-在來找pcre-config
包,辦法一樣
[root@localhost httpd-2.4.25]# yum search pcre
pcre-devel.i686 : Development files for pcre 《《這個包
pcre-devel.x86_64 : Development files for pcre
pcre-static.i686 : Static library for pcre
pcre-static.x86_64 : Static library for pcre
pcre-tools.x86_64 : Auxiliary utilities for pcre
pcre.i686 : Perl-compatible regular expression library
pcre.x86_64 : Perl-compatible regular expression library
- 安裝完畢以后在查包书妻,不過我這里已經(jīng)測試編譯完畢出現(xiàn)下面畫面
Server Version: 2.4.25
Install prefix: /app
C compiler: gcc -std=gnu99
CFLAGS: -pthread
LDFLAGS:
LIBS:
CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
C preprocessor: gcc -E
- 那我們開始編譯船响,上面只是測試編譯,現(xiàn)在開始正式編譯
- 用到的工具是
make
編譯必須在解壓的路徑才有效果切記切記 - 開始編譯:出現(xiàn)下面畫面就表示
[root@localhost httpd-2.4.25]# make
- 出現(xiàn)下面畫面表示編譯完成
-avoid-version mod_rewrite.lo
make[4]: Leaving directory `/httpd-2.4.25/modules/mappers'
make[3]: Leaving directory `/httpd-2.4.25/modules/mappers'
make[2]: Leaving directory `/httpd-2.4.25/modules'
make[2]: Entering directory `/httpd-2.4.25/support'
make[2]: Leaving directory `/httpd-2.4.25/support'
make[1]: Leaving directory `/httpd-2.4.25'
- 那我們開始安裝可以用命令
make install
來安裝
[root@localhost httpd-2.4.25]# make install
- 出現(xiàn)下面畫面就表示安裝完成
Installing configuration files
mkdir /app/conf
mkdir /app/conf/extra
mkdir /app/conf/original
mkdir /app/conf/original/extra
Installing HTML documents
mkdir /app/htdocs
Installing error documents
mkdir /app/error
Installing icons
mkdir /app/icons
mkdir /app/logs
Installing CGIs
mkdir /app/cgi-bin
Installing header files
mkdir /app/include
Installing build system files
mkdir /app/build
Installing man pages and online manual
mkdir /app/man
mkdir /app/man/man1
mkdir /app/man/man8
mkdir /app/manual
make[1]: Leaving directory `/httpd-2.4.25'
- 就表示我們軟件已經(jīng)編譯安裝完成需要開啟服務(wù)驻子,就可以用了