AnIntroductiontoGCC读书笔记Word文档格式.docx
- 文档编号:14887802
- 上传时间:2022-10-25
- 格式:DOCX
- 页数:14
- 大小:22.95KB
AnIntroductiontoGCC读书笔记Word文档格式.docx
《AnIntroductiontoGCC读书笔记Word文档格式.docx》由会员分享,可在线阅读,更多相关《AnIntroductiontoGCC读书笔记Word文档格式.docx(14页珍藏版)》请在冰豆网上搜索。
error.Itisrecommendedthatyoualwaysusethis!
ii.–o:
Thisoptionisusuallygivenasthelastargumentonthecommandline.Ifitisomitted,theoutputiswrittentoadefaultfilecalled‘***.out’.
b)Errordebugging:
i.ThemessagesproducedbyGCCalwayshavetheformfile:
line-number:
message.
2.Compilingmultiplesourcefiles
a)Differencebetween#include"
FILE.h"
and#include<
FILE.h>
i.#include"
Searchesinthecurrentdirectoryfirstthenthesystemheaderfiledirectory.
ii.#include<
onlysearchesinthesystemheaderfiledirectory.
b)gcc-Wallmain.chello_fn.c-onewhello
i.Notethathello.hwillbeincludedautomatically.
3.Compilingfilesindependently
a)Why:
Ifaprogramisstoredinasinglefilethenanychangetoanindividualfunctionrequiresthewholeprogramtoberecompiledtoproduceanewexecutable.
b)Thesourcefilesarecompiledseparatelyandthenlinkedtogether—atwostageprocess.
i.Firststage:
.o,anobjectfile.
ii.Secondstage:
theobjectfilesaremergedtogetherbyaseparateprogramcalledthelinker.
c)Creatingobjectfilesfromsourcefiles
i.gcc-Wall-cmain.c
-c:
compileasourcefileintoanobjectfile
ii.Containingthemachinecodeforthemainfunction,hasanexternalreferencetohello(),buttheexactmemoryaddressisnotdecided.
iii.Noneedtoadd–ooption
iv.Noneedtoputtheheaderfile‘hello.h’onthecommandline,
d)Creatingexecutablesfromobjectfiles
i.gccmain.ohello_fn.o-ohello
ii.Noneedtousethe‘-Wall’warningoption:
filehasbeencompiled.
iii.Failsonlyiftherearereferenceswhichcannotberesolved
e)Linkorderofobjectfiles
ii.Objectfilewhichcontainsthedefinitionofafunctionshouldappearafteranyfileswhichcallthatfunction.
f)Recompilingandrelinking
i.Iftheprototypeofafunctionhaschanged,itisnecessarytomodifyandrecompilealloftheothersourcefileswhichuseit.
ii.Linkingisfasterthancompilation
g)Linkingwithexternallibraries
i.Themostcommonuseoflibrariesistoprovidesystemfunctions.
ii.Librariesaretypicallystoredinspecialarchivefileswiththeextension‘.a’,referredtoasstaticlibraries
iii.Usingarcommandtocreateastaticlibrary
iv.Thedefaultlibraryfileislib.a,whenwereferredotherfunction,suchasmath.h,wewillneedlibm.a
v.gcc-Wallcalc.c-lm-ocalc
vi.Thecompileroption‘-lNAME’willattempttolinkobjectfileswithalibraryfile‘libNAME.a’inthestandardlibrarydirectories.
h)Linkorderoflibraries
i.Containingthedefinitionofafunctionshouldappearafteranysourcefilesorobjectfileswhichuseit.
ii.Alibrarywhichcallsanexternalfunctiondefinedinanotherlibraryshouldappearbeforethelibrarycontainingthefunction.
iii.gcc-Walldata.c-lglpk-lm
iv.libglpk.acallsfunctionsinlibm.a
i)Usinglibraryheaderfile:
Ifyouwronglyomittheincludeheaderfile,youcanonlydetectthiserrorby–Wall
Chapter3:
compilationoptions
1.Settingsearchpaths
a)Bydefault,gccsearches
i.Thefollowingdirectoriesforheaderfiles:
1./usr/local/include/
2./usr/include/
ii.Thefollowingdirectoriesforlibraries:
1./usr/local/lib/
2./usr/lib/
iii.Aheaderfilefoundin‘/usr/local/include’takesprecedenceoverafilewiththesamenamein‘/usr/include’.
iv.Thecompileroptions‘-I’and‘-L’addnewdirectoriestothebeginningoftheincludepathandlibrarysearchpathrespectively.
b)Searchpathexample
i.gcc-Wall-I/opt/gdbm-1.8.3/include-L/opt/gdbm-1.8.3/libdbmain.c–lgdbm
-I:
addnewdirectorytotheheaderfilesearchset.
-L:
addnewdirectorytothelibrarysearchset.
ii.Youshouldneverplacetheabsolutepathsofheaderfilesin#includestatementsinyoursourcecode,asthiswillpreventtheprogramfromcompilingonothersystems
c)Environmentvariables
i.Setin.bash_profile
ii.AdditionaldirectoriescanbeaddedtotheincludepathusingtheenvironmentvariableC_INCLUDE_PATH(forCheaderfiles)orCPLUS_INCLUDE_PATH(forC++headerfiles).
iii.C_INCLUDE_PATH=/opt/gdbm-1.8.3/include
C_INCLUDE_PATH=.:
/opt/gdbm-1.8.3/include:
/net/include
exportC_INCLUDE_PATH
LIBRARY_PATH=/opt/gdbm-1.8.3/lib
exportLIBRARY_PATH
d)Extendedsearchpaths
i.gcc-I.-I/opt/gdbm-1.8.3/include-I/net/include-L.-L/opt/gdbm-1.8.3/lib-L/net/lib
Addmultiplesearchpaths
e)Exactsearchorder.
i.Command-lineoptions‘-I’and‘-L’,fromlefttoright
ii.Directoriesspecifiedbyenvironmentvariables,suchasC_INCLUDE_PATHandLIBRARY_PATH
iii.Defaultsystemdirectories
2.Sharedlibrariesandstaticlibraries
a)Staticlibraries
i.‘.a’files
ii.Whenaprogrami
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- AnIntroductiontoGCC 读书笔记
![提示](https://static.bdocx.com/images/bang_tan.gif)