你應該不會期待在 linux 有 GW/Qbasic 吧?? 在 Un*x 中, 系統內定的語言是 C,
不管你是喜歡還是討厭它. 當然還有其它的語言可以用 (FORTRAN, Pascal, Lisp, Bacic
.. 但沒有 Turbo Pascal ^Q^ ).
假設你懂得 C.. 假如你曾經被 Turbo C++ 或是它在 DOS 下的兄弟們寵愛過, 那這里
有兩句話恐怕不啻晴天霹靂: Linux 下的 C 編譯器叫作 gcc, 但, 它沒有 IDE 環境,
沒有線上求助系統, 沒有整合式除錯器,..等等. 只有一個命令列的編譯器, 但強大
且有效率. 以下這個命令可以編譯你已寫好的 hello.c :
$ gcc hello.c
這樣會產生一個 a.out 的執行檔. 假如你想讓 gcc 造出其它檔名的執行檔, 鍵入
$ gcc -o hola hello.c
要聯結一個程式庫, 你要在 gcc 後加上一個 -l<arg> 的選項. 比如說要聯結 math
library
$ gcc -o mathPRog mathprog.c -lm
( -l<arg> 會迫使 gcc 聯結 /usr/lib/lib<arg>.a; 因此, -lm 會聯結
/usr/lib/libm.a)
對小程式來說, 這是一個好方法. 但是若程式是由數個 source files 組成, 我們可能
會需要 make 這個程式. 假設我們已經寫好一個語法分析程式 parser.c, 它 #include
了兩個 .h : parser.h , xy.h. 現在, 有個 calc.c 需要使用到 parser.c 中的功能.
這樣該怎麼辦??
我們可以寫一個叫作 makefile 的檔案, 告訴編譯器所有 source 和 object files
間的關系, 在這個例子里,
# This is makefile, used to compile calc.c
# Press the <TAB> key at appropriate positions!
calc: calc.o parser.o
<TAB>gcc -o calc calc.o parser.o -lm
# calc depends on two object files: calc.o and parser.o
calc.o: calc.c parser.h
<TAB>gcc -c calc.c
# calc.o depends on two source files
parser.o: parser.c parser.h xy.h
<TAB>gcc -c parser.c
# parser.o depends on three source files
# end of makefile.
儲存, 然後鍵入
$ make
以便編譯程式. 或者, 這個檔案被存在 calc.mak 里, 那麼就必需
$ make -f calc.mak
當然, 請參閱 Man pages 以得到更多的資訊.
此外, 某些函數的用法在 man pages 可以找得到, 例如
$ man printf