AnIntroductiontoGCC读书笔记Word文档格式.docx

上传人:b****2 文档编号:14887802 上传时间:2022-10-25 格式:DOCX 页数:14 大小:22.95KB
下载 相关 举报
AnIntroductiontoGCC读书笔记Word文档格式.docx_第1页
第1页 / 共14页
AnIntroductiontoGCC读书笔记Word文档格式.docx_第2页
第2页 / 共14页
AnIntroductiontoGCC读书笔记Word文档格式.docx_第3页
第3页 / 共14页
AnIntroductiontoGCC读书笔记Word文档格式.docx_第4页
第4页 / 共14页
AnIntroductiontoGCC读书笔记Word文档格式.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

AnIntroductiontoGCC读书笔记Word文档格式.docx

《AnIntroductiontoGCC读书笔记Word文档格式.docx》由会员分享,可在线阅读,更多相关《AnIntroductiontoGCC读书笔记Word文档格式.docx(14页珍藏版)》请在冰豆网上搜索。

AnIntroductiontoGCC读书笔记Word文档格式.docx

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

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 农林牧渔 > 林学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1