標籤:style blog http 使用 os io 檔案 for
現在很多項目都在使用GUI編譯器,Kdevelop\Eclipse等等,誠然它給我們提供了極大地便利,但我們仍需要簡單瞭解編譯的過程。本文旨在簡單敘述由源碼(*.cpp & *.h)經過編譯得到可執行檔的過程,以及對產生的中間檔案做一個簡單的講解,後面給出一個example。
| 1. autoscan:掃描原始碼以搜尋普通的可移植性問題,比如檢查編譯器,庫,標頭檔等,組建檔案configure.scan,它是configure.ac的一個雛形。 過程:your source files --> [autoscan*] --> [configure.scan] --> configure.ac |
| 2. aclocal:根據已經安裝的宏,使用者定義宏和acinclude.m4檔案中的宏將configure.ac檔案所需要的宏集中定義到檔案aclocal.m4中。 aclocal是一個perl指令碼程式,它的定義是:"aclocal - create aclocal.m4 by scanning configure.ac" |
| 3. automake:automake將Makefile.am中定義的結構建立Makefile.in。 然後configure指令碼將產生的Makefile.in檔案轉換 為Makefile。如果在configure.ac中定義了一些特殊的宏,比如AC_PROG_LIBTOOL,它會調用libtoolize,否則它 會自己產生config.guess和config.sub |
| 4. autoconf:將configure.ac中的宏展開,產生configure指令碼。這個過程可能要用到aclocal.m4中定義的宏。 |
| 6. make過程 [autoconfig.h]—. +-----> make* ----->程式 |
| Never mind, That‘s not a problem~, there is nothing to be afraid of, cause the following example I provided will show you the guide. perhaps you should type the commands one by one for better understanding. |
| 在/home/panda/目錄下vi一個hello.cpp檔案(當然,你的[*.cpp&*.h]都可以放在這裡,但必須保證沒有文法上的錯誤),並complie它: >>>>cd /home/panda/hello/ >>>>vi hello.cpp/*編寫源檔案hello.cpp*/ |
| [CODE] #include<iostream> using namespace std; int main() { cout<<"Hello,RoboCup."<<endl; return 0; } [/CODE] |
| >>>>autoscan >>>>mv configure.scan configure.in >>>>vi configure.in |
| /*已經產生了configure.scan,autoscan.log*/ /*將configure.scan 修改為 configure.in,最後修改的內容如下*/ |
| [CODE] #-*- Autoconf -*- # Process this file with autoconf to produce a configure script. |
| AC_PREREQ(2.59) AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS) AC_CONFIG_SRCDIR([hello.cpp]) #AC_CONFIG_HEADER([config.h]) AM_INIT_AUTOMAKE(hello, 1.0) # Checks for programs. AC_PROG_CC |
| # Checks for header files. |
| # Checks for typedefs, structures, and compiler characteristics. |
| # Checks for library functions. AC_OUTPUT(Makefile) [/CODE] |
| >>>>aclocal/*產生 aclocal.m4 和 autom4te.cache (產生aclocal.m4的過程中涉及到configure.in)*/ >>>>ls >>>> aclocal.m4 autom4te.cache autoscan.log configure.in hello.cpp >>>>antoconf/*產生 configure (根據 configure.in, 和 aclocal.m4)*/ >>>>ls >>>>aclocal.m4 autom4te.cache autoscan.log configure configure.in hello.cpp >>>>vi Makefile.am/*編寫Makefile.am*/ |
| [CODE] AUTOMAKE_OPTIONS= foreign bin_PROGRAMS= hello hello_SOURCES= hello.cpp [/CODE] |
| >>>>automake >>>>automake --add-missing/*產生 Makefile.in, depcomp, install-sh, 和 missing (根據 Makefile.am, 和 aclocal.m4)*/ >>>>ls >>>>aclocal.m4 autom4te.cache autoscan.log configure configure.in depcomp hello.cpp install-sh Makefile.am Makefile.in missing >>>>configure/*Makefile, config.log, 和 config.status*/ /*紅色表示在終端中輸入的命令,斜體表示源碼*/ |
| 現在看不明白,或者不是很清楚都沒有關係,只做瞭解就好,可以將本文保留下來,隨著你們學習的深入,等到時機成熟的時候再作參考,便會對Linux下C++的編譯過程會理解的更加透徹。 |
文檔下載連結:http://download.csdn.net/detail/klcf0220/7703221