1.,..,, GNU,, GNU..,. GNU..
4 0 B e g in n in g Lin u x P ro g ra m m in g 3? AT&T. Digital Equipment PDP 1970., PC.,. (Single Unix Specification),,. IEEE(Institute of Electrical and Electronic Engineers, ) (P1003 POSIX ). SCO. SCO (Unixware), IBM AIX, HP HP-UX, Sun. FreeBSD.,. POSIX.. 19. ( ). C,,. ( )..
1 4 1 :..,. :..... :.. dbm. (filter) :.,.,.. :..,,. ct ags (cross-reference system). (regular expression). :.....? ( ).,...
4 2 B e g in n in g Lin u x P ro g ra m m in g 3. Andy Tanenbaum Minix.. CPU. x86 PC Sun Sparc, IBM PowerPC, Itanium, PDA Playstation2.. GNU (Fre e Softwa re Foundation)..... GNU (General Public License),.,.. GNU Emacs., GNU (GNU GNU's Not Unix ). GNU. GNU. GNU. GNU GNU (General Public License, GPL), ht t p :/ / www.gnu.or g.
1 4 3 (copyleft; copyright ).. GPL GNU. GCC: GNU (Compiler Collection), GNU C. G+ + : C+ +, GCC. GDB: GNU make : make Bison: yacc (parser) bash: GNU Emacs : GPL. Gimp,,,, (GNOME KDE). GNOME KDE 16 17., GNU. GNU GNU/. ht t p :/ / www.gnu.or g..,.,. GNU.,. (distribution, (flavor) ) CD-ROM.
4 4 B e g in n in g Lin u x P ro g ra m m in g 3. X. CD. ( x8 6 ) (Red Hat), (SuSE), (Debian) GNU/. C. C C. C.. 1969 PDP 7. (Dennis Ritchie) C, 1973 (Ken Thompson) C., C.., CD-ROM FTP (archive).. Ada C C+ + Eiffe l Fo rth Fo rtra n Icon J ava J avascript Lis p Modula 2 Modula 3 Obe ron Objective C Pasca l Pe rl PostScript Pro log Python S che me S ma llta lk S QL Tcl/ Tk Bourne S he ll (bash) 2. C. C. C.
1 4 5.., Windows. exe.. Windows.bat. cmd (interprete) (BASIC).. 2. ( )... (bash ). Windows.,. PATH, Windows.,.. / bi n :, / usr / bi n :, / usr / l ocal / bi n :, r oot PATH. / sbi n / usr / sbi n. / opt. PATH. PATH. (:) PATH. MS-DOS Windows (;) ( :. Windows!). PATH.
4 6 B e g in n in g Lin u x P ro g ra m m in g 3 / us r / l oc al / b i n : / bi n : / us r / bi n :. : / home / ne i l / bi n : / u s r / X11R6/ bi n PATH, (.),, X. (/ ). Windows (\ ).. C POSIX C c89. C cc. C. C cc. POSIX, cc. C, c89.., c89, cc, gcc C. C GNU C gcc. C cc. gcc. gcc, gcc C ANSI. gcc gcc. ht t p :/ / www.gnu.or g. gcc. - C C.. Hello World. 1. hel l o.c.
1 4 7 #i nc l ude <s t di o.h> i nt mai n () { pr i nt f ("He l l o Wor l d\ n " ) ; exi t (0) ; }.. vi, emacs. emacs. emacs Ctrl+ H t. emacs. emacs Ctrl+ H i. emacs. 2.. $ g c c - o he l l o he l l o. c $. / he l l o He l l o Wor l d $ GNU C ( cc ) C hel l o.,.,. C. (Software Development),.. hel l o. PATH, hel l o. PATH hel l o,. PATH hel l o.
4 8 B e g in n in g Lin u x P ro g ra m m in g 3,. / (. / hel l o).. - o a. out (assembler output ).. a.out. a.out. a.out.... / usr / bi n. / usr / l ocal / bi n / opt. / usr / l ocal.,. / usr. / usr / l ocal. / usr / l o cal.. X. / usr / X11. (Revision) 6 / usr / X11R6, XFree XFree86.. Sun / usr / openwi n. GNU gcc( ) / usr / bi n / usr / l ocal / bi n..,. / usr / l i b/ gcc- l i b/
1 4 9. / usr / l i b/ gcc- l i b/ i 486- suse- l i nux/ 3.3/. GNU C/C++ GNU. C,. C / usr / i ncl ude. / usr / i ncl ude/ sys / usr / i ncl ude/ l i nux... X / usr / i ncl ude/ X11 GNU C++ / usr / i ncl ude/ g++. C - I. $ g c c - I / us r / op e nwi n/ i nc l ude f r ed. c / usr / openwi n/ i ncl ude. fr ed. c. C (man gcc). gr ep. #defi ne. / usr / i ncl ude, gr ep. $ g r ep EXI T_ *. h... s t dl i b. h : #de f i ne EXI T_ FAI LURE 1 / * Fai l i ng exi t s t at us. */ s t dl i b. h : #de f i ne EXI T_ SUCCESS 0 / * Succe s s f ul ex i t s t at us. */... $ gr ep.h EXI T_. st dl i b.h.
5 0 B e g in n in g Lin u x P ro g ra m m in g 3.. (cur ses ncur ses ), (dbm ).. / l i b / usr / l i b. C ( ). C. CPU.., (command line). l i b. (C c, m)... (static library). a (shared library). so( ). l s / usr/ l i b. - l., $ g c c - o f r ed f r ed. c / us r / l i b / l i bm. a fr ed.c fr ed C.. $ g c c - o f r ed f r ed. c - l m - l m(l m ) ( / usr / l i b) l i bm.a ( ). - l m.
1 5 1, - L., $ g c c - o x 11f r ed - L/ us r / ope nwi n/ l i b x 11f r e d. c - l X11 / usr / openwi n/ l i b l i bx11 x11fr ed..,.. - l C. (a rchive ).a. C / usr / l i b/ l i bc.a X11 / usr / X11/ l i b/ l i bx11.a. gcc - c ar(archive)..,. -,. fr ed bi l l,. 1. (fr ed.c bi l l. c).. #i nc l ude <s t di o.h> voi d f r ed (i nt ar g )
5 2 B e g in n in g Lin u x P ro g ra m m in g 3 { } pr i nt f (" f r ed : you pas s e d %d\ n ", ar g ) ;. #i nc l ude <s t di o. h> voi d bi l l (char *a r g ) { pr i nt f ("b i l l : you pas s e d %s \ n ", ar g ) ; } 2. (object file). - c C.. mai n. $ g c c - c b i l l. c f r ed. c $ l s *. o bi l l. o f r ed. o 3. bi l l.... fr ed. c bi l l. c.. / * */ l i b.h. f r ed bi l l. voi d bi l l (char *) ; voi d f r ed (i nt ) ; 4. (pr ogr am.c)..
1 5 3 #i nc l ude "l i b.h " i nt mai n () { bi l l ("He l l o Wor l d " ) ; exi t (0) ; } 5.. bi l l.o. $ g c c - c p r og r am. c $ g c c - o p r og r am pr og r am. o b i l l. o $. / pr og r am b i l l : you pas s e d He l l o Wor l d $ 6.. ar. ar,. ar ( ar ). $ ar c rv l i b f oo. a b i l l. o f r ed. o a - bi l l. o a - f r ed. o 7..,. r anl i b. GNU ( ). $ r anl i b l i b f oo. a.. $ g c c - o p r og r am pr og r am. o l i b f oo. a $. / pr og r am b i l l : you pas s e d He l l o Wor l d $
5 4 B e g in n in g Lin u x P ro g ra m m in g 3 - l., - L. $ g c c - o pr og r am pr og r am. o - L. - l f oo - L.. - l f oo l i bf oo.a( l i bfoo. so )., nm. pr ogr am l i bfoo.a, fr ed bi l l, pr ogr am bi l l... Windows. Windows func.o FUNC.OBJ l i b.a LIB.LIB pr ogr am PROGRAM.EXE..,...
1 5 5. / usr / l i b/ l i bm. so.,.,..,.. / usr / l i b/ l i bm. so (/ usr / l i b/ l i bm. so.n N, 6 ) (symbolic link),.,.. SuSe 8.2.. ( ) l d.so. l d- l i nux. so.2 l d- l sb. so. 1. / et c/ l d. so.conf. l dconf i g ( X X11 ). l dd.. $ l dd pr og r am l i bc. s o. 6 => / l i b / l i bc. s o. 6 (0x 4002a 000) / l i b / l d- l i nux. s o. 2 => / l i b / l d- l i nux. s o. 2 (0x 40000000 ) C (l i bc) (. so). 6...
5 6 B e g in n in g Lin u x P ro g ra m m in g 3 Windows (dynamic link library)..so.dll.. sa.lib..,.. man..,.. GNU i nfo. i nfo emacs i nfo. i nfo. i nfo /. - info GNU C. 1.. $ man g c c GCC (1) GNU GCC (1)
1 5 7 NAME gcc - GNU pr oj ec t C and C++ comp i l e r SYNOPSI S gcc [- c - S - E] [- s t d=s t anda r d ] [- g ] [- pg ] [- Ol eve l ] [-Wwar n... ] [- pedant i c ] [- I di r... ] [- Ldi r... ] [- Dmac r o [=de f n ]... ] [- Umac r o ] [- f opt i on... ] [- mmachi ne - opt i on... ] [- o out f i l e ] i n f i l e... Onl y t he mos t us e f ul opt i ons a r e l i s t ed he r e ; s ee be l ow f or t he r emai nde r. g++ accept s mos t l y t he s ame opt i ons as gcc. DESCRI PTI ON When we i nvoke GCC, i t nor mal l y doe s p r epr oc e s s i ng, com p i l at i on, as s embl y and l i nki ng. The ' ' ove r al l opt i ons ' ' a l l ow you t o s t op t hi s p r oce s s at an i nt e r medi at e s t age. For exampl e, t he - c opt i on s ay s not t o r un t he l i nke r. Then t he out put cons i s t s of ob j ect f i l e s out put by t he a s s embl e r.... Ot he r opt i ons a r e pas s ed on t o one s t age of pr oce s s i ng. Some opt i ons cont r ol t he pr ep r oce s s or and ot he r s t he com p i l e r i t s e l f. Yet ot he r opt i ons cont r ol t he as s emb l e r and l i nke r ; mos t of t he s e a r e not document ed he r e, s i nc e we r ar e l y need t o u s e any o f t hem.. GNU C( C++). (spacebar) ( ) q. 2. GNU C i nfo. $ i nf o g c c Fi l e : gc c. i n f o, Node : Top, Next : G++ and GCC, Up : (DI R) I nt r oduct i on
5 8 B e g in n in g Lin u x P ro g ra m m in g 3 ************ Thi s manual document s how t o us e t he GNU compi l e r s, as we l l as t he i r f e at ur e s and i ncompat i bi l i t i e s, and how t o r epor t bugs. I t cor r e sponds t o GCC ve r s i on 3. 3. The i nt e r nal s of t he GNU compi l e r s, i nc l udi ng how t o por t t hem t o new t ar get s and s ome i n f or mat i on about how t o wr i t e f r ont ends f or new l anguage s, ar e document ed i n a s epar at e manua l. *Not e I nt r oduct i on : (gcc i nt ) Top. * Menu : * G++ and GCC: : We can compi l e C or C++ Appl i cat i ons. * St andar ds : : Language s t andar ds s uppor t ed by GCC. * I nvoki ng GCC: : Command opt i ons suppor t e d by ' gc c '. * C Impl ement at i on : : How GCC i mpl ement s t he I SO C s pec i f i c at i on. * C Ext ens i ons : : GNU ext ens i on s t o t he C l angu age f ami l y. * C++ Ext ensi ons : : GNU ext ensi ons t o t he C++ l anguage. * Obj ec t i ve - C: : GNU Obj ect i ve - C r unt i me f e at ur e s. * Compat i bi l i t y : : Bi nar y Compat i bi l i t y - - zz- I nf o : (gcc. i n f o. gz ) Top, 40 l i ne s - - Top- - Subf i l e : gcc. i nf o- 1. gz- - *** Tags o Wel come t o Inf o ver si on 4. 5. Type? f or hel p, m for menu i t em.,... GNU C. i nfo i nfo. Ctrl+H i nfo. i nfo,.... C, Windows.