codewarrior軟件與編程的講解完整版_第1頁
codewarrior軟件與編程的講解完整版_第2頁
codewarrior軟件與編程的講解完整版_第3頁
codewarrior軟件與編程的講解完整版_第4頁
codewarrior軟件與編程的講解完整版_第5頁
已閱讀5頁,還剩92頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

CodeWarrior使用教程第一課認(rèn)識(shí)CodeWarriorTranslatedfrom?CodeWarriorU.COMCodeWarrior?能做些什么?????當(dāng)你知道自己能寫更好的程序時(shí),你一定不會(huì)再使用別人開發(fā)的應(yīng)用程序。但是常常會(huì)發(fā)生這種情況,就是當(dāng)你寫了無數(shù)行代碼后,卻找不到使得整個(gè)程序出錯(cuò)的那一行代碼,導(dǎo)致根本沒法編譯和鏈接整個(gè)程序。這可能更令人灰心喪氣。????本文將告訴你如何使用?CodeWarrior?這一工具解決上述問題。????從現(xiàn)在開始,我們將集中精力學(xué)習(xí)如何在?CodeWarrior?中使用?C/C++?進(jìn)行編程。為了學(xué)習(xí)本課程,你必須已經(jīng)能夠比較熟練地使用上述兩種語言之一。CodeWarrior?也可以支持?Java?開發(fā),但那是另一門課程的內(nèi)容。本課程僅限于在?Windows?平臺(tái)上使用?CodeWarrior?進(jìn)行的開發(fā)。一旦你精通了?CodeWarrior?編程后,你可以試試在其它平臺(tái)上使用?CodeWarrior。本文中討論過的大部分內(nèi)容都可以應(yīng)用到開發(fā)?Mac?應(yīng)用程序中。???CodeWarrior?能夠自動(dòng)地檢查代碼中的明顯錯(cuò)誤,它通過一個(gè)集成的調(diào)試器和編輯器來掃描你的代碼,以找到并減少明顯的錯(cuò)誤,然后編譯并鏈接程序以便計(jì)算機(jī)能夠理解并執(zhí)行你的程序。你所使用過的每個(gè)應(yīng)用程序都經(jīng)過了使用象?CodeWorrior?這樣的開發(fā)工具進(jìn)行編碼、編譯、編輯、鏈接和調(diào)試的過程。現(xiàn)在你在我們的指導(dǎo)下,自己也可以去做這些工作了。????你可以使用?CodeWarrior?來編寫你能夠想象得到的任何一種類型的程序。如果你是一個(gè)初學(xué)者,你可以選擇編寫一個(gè)應(yīng)用程序(比如一個(gè)可執(zhí)行程序),比如象微軟公司的文本編輯器?WordPad?這樣的應(yīng)用程序。????應(yīng)用程序可能是最容易編寫的程序了,而那些龐大的商業(yè)軟件,比如象?AdobePhotoshop,MicrosoftWord?以及?CodeWarrior?軟件都是極其復(fù)雜的。其它類型的程序指的是控制面板(controlpanels),動(dòng)態(tài)鏈接庫(dynamiclinkedlibraries,DLLs)?和插件(plug-ins)。我們先來簡(jiǎn)單的討論一下這些類型的程序。????在?Windows沖,控制面板程序是一些(通常比較小的)存放在控制面板目錄下的程序,可以在開始菜單的控制面板項(xiàng)中看到它們。控制面板實(shí)際上是設(shè)置系統(tǒng)功能的一個(gè)簡(jiǎn)單界面,比如可以在控制面板中完成諸如設(shè)置音量和鼠標(biāo)移動(dòng)速度這樣一些參數(shù)。????動(dòng)態(tài)鏈接庫?(DLLs)?提供了一些很有用的被系統(tǒng)和應(yīng)用程序共享的函數(shù)。通常它們都是沒有用戶界面的。????插件?(Plug-ins)?有點(diǎn)類似于?DLLs,插件也是可供其它軟件使用的小程序,但插件只能被特定的軟件使用。比如說,Photoshop?的插件允許程序員方便地?cái)U(kuò)展?Photoshop?的功能,而不需要去修改它的源代碼。同樣的,許多?Web?瀏覽器也使用插件來增加功能,或者為了讓你能夠看到頁面上的新的內(nèi)容類型。實(shí)際上,有許多程序,包括?CodeWarrior,都使用這種插件結(jié)構(gòu)。????一旦你掌握了?CodeWarior?和你所使用的操作系統(tǒng)的編程接口時(shí),你可以編寫許多其它類型的程序。實(shí)際上,本課程也是你深入學(xué)習(xí)其它編程方法的基礎(chǔ)課程。你已經(jīng)找到了一個(gè)最優(yōu)秀的地方開始你的編程之旅。好,現(xiàn)在請(qǐng)坐好,放松,去吸取這門課程的精華吧,你將踏上一條成為一個(gè)編程武士的道路!CodeWarrior?入門???CodeWarrior?是一個(gè)復(fù)雜的應(yīng)用程序,你必須花點(diǎn)時(shí)間來了解它的各種各樣的組件和功能。第一課將講述CodeWarriorIDE?的安裝。我們將學(xué)習(xí)菜單、窗口和其它的一些方面。建議你最好一邊學(xué)習(xí)本課程,一邊學(xué)習(xí)使用?CodeWarrior?的集成開發(fā)環(huán)境。我們從運(yùn)行?CodeWarrior?開始,如果你按照默認(rèn)方式安裝的CodeWarrior?軟件,那么在?Windows?的桌面上將會(huì)有一個(gè)該軟件的快捷方式圖標(biāo)。雙擊該圖標(biāo)啟動(dòng)CodeWarrior?的集成開發(fā)環(huán)境。如果在?Windows?桌面上沒有這個(gè)快捷圖標(biāo)(這種情況經(jīng)常發(fā)生),你可以在C:\ProgramFiles\Metrowerks\CodeWarrior\Bin?中找到?IDE.exe?文件,然后運(yùn)行它。工具條啟動(dòng)?CodeWarrior?后,你將會(huì)看到,在屏幕上方的菜單下面有一個(gè)工具條。這個(gè)工具條(見圖1-1)包含了一些常用菜單項(xiàng)的快捷方式。在后面的章節(jié)中,你將學(xué)到如何設(shè)置這個(gè)工具條,甚至是整個(gè)?IDE?環(huán)境?,F(xiàn)在,你應(yīng)記住,這個(gè)工具條用于快捷使用?IDE?中的功能。圖?1-1:CodeWarriorIDE的工具條文件菜單???CodeWarriorIDE?的菜單是按照標(biāo)準(zhǔn)方式設(shè)置的。其中的文件菜單用于處理和文件相關(guān)的一些操作,比如創(chuàng)建、打開、保存和打印等等。編輯菜單???CodeWarrior?的編輯菜單和其它的?Windows?應(yīng)用程序也很相像。其中包括了剪切、復(fù)制和粘貼等操作,以及其它一些使得程序員能夠更方便地管理源碼版面布局的選項(xiàng)。在編輯菜單中還有一個(gè)?Preferences?項(xiàng),我們?cè)谶@一課的后面將提到它。查看菜單查看菜單(圖1-2)用于安排工具條和其它窗口在?CodeWarrior?環(huán)境中如何顯示的選項(xiàng)。所謂的“其它窗口”包括許多特殊的窗口,比如觀察點(diǎn)(Watchpoints)窗口,表達(dá)式(Expressions)窗口,過程(Processes)窗口和全局變量(GlobalVariables)窗口等。圖?1-2:?查看菜單中的工具條子菜單查找菜單????查找菜單用于在單個(gè)文件或硬盤的目錄中查找指定的代碼。你可以使用它來方便地替換文本塊或在你的代碼中搜索指定的項(xiàng)目。即使是在小工程中使用這個(gè)工具也非常方便。工程菜單????工程菜單中的工具用于管理?CodeWarrior?工程。一個(gè)工程包括組成你正在編寫的程序的所有的文件,包括頭文件、源代碼和庫文件。工程窗口顯示了所有這些文件的名稱。我們將在第二課中深入討論這部分內(nèi)容。調(diào)試菜單????這是在編制程序中最常用到的工具。我們將在第五課中詳細(xì)介紹它的使用方法。窗口菜單????用于在?CodeWarrior?環(huán)境管理窗口顯示方式的菜單。幫助菜單????通過幫助菜單可以到網(wǎng)上尋求關(guān)于PCodeWarrior?任何問題的在線解答。夠酷的吧?了解?CodeWarrior?集成開發(fā)環(huán)境的設(shè)置???CodeWarriorIDE?提供了許多設(shè)置以便讓你定制你的工作環(huán)境。當(dāng)你選擇了編輯菜單中的?Preferences?項(xiàng)時(shí),你將會(huì)看到一個(gè)設(shè)置對(duì)話框(如圖1-3)o在該對(duì)話框中,有控制?CodeWarrior?編輯器、調(diào)試器和其它許多功能的界面和行為的選項(xiàng)。在這一節(jié)中,我們將學(xué)習(xí)這些設(shè)置的使用。圖?1-3:?<置對(duì)話框????你可以在自己的PCodeWarrior?中試試上述這些設(shè)置項(xiàng)。你可以先點(diǎn)擊問號(hào)標(biāo)志,然后點(diǎn)擊你感興趣的項(xiàng)目,就可以得到一個(gè)有關(guān)該項(xiàng)目的用途的簡(jiǎn)短介紹,也可以從幫助菜單中得到更詳細(xì)的信息。通用設(shè)置編譯設(shè)置(BuildSettings):?選擇是否在執(zhí)行編譯之前保存已打開的源文件,以及有多少內(nèi)存被用于編譯工作;IDE?之外(IDEExtras):?幾個(gè)獨(dú)立的設(shè)置。比如指定PCodeWarrior?是否使用一個(gè)第三方的文本編輯器——因?yàn)榧傻木庉嬈鞑⒉皇呛芡昝?,這可以通過指定一個(gè)你慣用的編輯器來替代它;插件設(shè)置(Plug-InSettings):?供插件開發(fā)商調(diào)試他們的插件;隱藏文件夾(ShieldedFolders):?^這里指定的文件夾在工程設(shè)計(jì)期間,或執(zhí)行查找和比較操作期間,將要被忽略掉。如果在你的工程級(jí)有一個(gè)巨大的“數(shù)據(jù)”文件目錄,而你又不想讓這些文件降低CodeWarrior?的操作速度時(shí),這個(gè)設(shè)置就很管用了;資料樹(SourceTrees):?用于指定?CodeWarrior?在編譯程序時(shí)用不著的目錄。編輯器設(shè)置編輯器設(shè)置(EditorSettings):?幾個(gè)用于定制編輯器顯示、管理文本和窗口的設(shè)置項(xiàng);字體和制表符(FontsandTabs):?設(shè)置編輯器中的文本大小、字體、制表符和其它顯示設(shè)置;文本顏色(TextColors):?用于指定特定語言元素(比如程序的注釋)在編輯窗口中的顯示的顏色。調(diào)試器設(shè)置顯示設(shè)置(DisplaySettings):?幾個(gè)用于定制調(diào)試器顯示的設(shè)置項(xiàng);視窗化(Windowing):?設(shè)定調(diào)試器如何管理它的窗口(比如隱藏所有打開的編輯器窗口);全局設(shè)置(GlobalSettings):?幾個(gè)用于定制調(diào)試器在全局層次如何工作的設(shè)置。比如當(dāng)一個(gè)包含了程序調(diào)試信息的文件被打開時(shí),是否啟動(dòng)這個(gè)程序;遠(yuǎn)程連接(RemoteConnections):?允許通過PTCP/IP?進(jìn)行遠(yuǎn)程調(diào)試。這樣,你就可以在地球的另一邊調(diào)試你的軟件了;Java?設(shè)置/Java?調(diào)試(JavaSettings/JavaDebugging):?允許你設(shè)置特定的?Java?編程語言選項(xiàng)。本課程不涉及這部分內(nèi)容。RAD?工具Layout?編輯器:?幾個(gè)用于在?CodeWmior?中定制快速應(yīng)用程序開發(fā)工具的使用的設(shè)置。????正如你所見到的,CodeWarrior?有許多設(shè)置項(xiàng)和選項(xiàng)。設(shè)置完后點(diǎn)擊“Save”按鈕保存你所作的修改,點(diǎn)擊“Close”按鈕將忽略你所作的所有修改。在進(jìn)入下一節(jié)課之前,多練習(xí)幾次。最后請(qǐng)確認(rèn)“默認(rèn)的文本文件格式(DefaultTextFileFormat)”(在編輯器設(shè)置面板中)保持為?DOS?設(shè)置。(待續(xù))附原文:Lesson1:GettingtoKnowCodeWarriorWhatWillCodeWarriorDoforMe?Itcanbefrustratingtouseotherpeople'sapplicationswhenyouknowyoucanmakesomethingbetter.Butitcanalsobefrustratingwhenyouhaveazillionlinesofcodeandcan'tfindtheonetypothat'smakingthewholeapplicationgokablooey--nottomentiongettingitallcompiledandlinkedandsoon.Thisiswhyyouarehere.AndthisiswhyCodeWarriorwascreated.Fornow,we'llfocusonwritingprogramsinCodeWarriorusingtheCorC++programminglanguages.Thiscourseassumesthatyou'reprettycomfortableusingatleastoneoftheselanguages.CodeWarrioralsosupportsJavadevelopment,butthatwillbecoveredinaseparateclass.ThiscourseconcernsitselfwithWindowsplatformdevelopment.OnceyougetreallygoodatprogrammingwithCodeWarrior,youcanexploretheotherplatformsforwhichtoolshavebeendesigned.MuchofwhatwillbediscussedherecanalsobeappliedtodevelopingMacapplications.CodeWarriorautomaticallychecksyourcodeforobviouserrors,helpsyouscanitforlessobviousones(viaanintegrateddebuggerandeditor),andthencompilesandlinksthecodesothatyourcomputercanunderstandandexecuteyourprogram.Everyapplicationthatyouhaveusedhasbeenthroughthecoding,compiling,editing,linking,anddebuggingprocess,usingtoolslikeCodeWarrior.Nowyoucandoittoo!Butwestillhavetoteachyouhow.UsingCodeWarrior,youcanwritejustaboutanytypeofprogramyoucanimagine.Ifyouareabeginner,youmaychoosetowriteanapplication(alsoknownasanexecutable)asyourfirstprogram.YoumightchoosetocreatesomethingasbasicasWordPad,Microsoft'stexteditor,forexample.Applicationsareprobablythesimplesttypeofprogramtowrite,thoughlargecommercialoneslikeAdobePhotoshop,MicrosoftWordandevenCodeWarrioritselfarequitecomplex.Otherprogramtypesincludecontrolpanels,dynamiclinkedlibraries(DLLs),andplug-ins.Let'stalkaboutthesetypesforaminute.UnderWindows,controlpanelsarethose(usuallysmall)programsthatarestoredinyourControlPanelsdirectoryandvisibleintheControlPanelsectionontheStartmenu.Thecontrolpanelitselfissimplyaninterfacetoasystem-widefeature,likesettingthesoundvolumeorthemouse'smotionspeed,forexample.DLLssupplyusefulfunctionsthataresharedbytheoperatingsystemandapplications.Theytypicallydon'thaveauserinterfacePlug-insaresimilartoDLLsinthattheyprovidesmallpiecesofcodethatareusedbyothersoftware.However,asingleprogramtypicallyusesthiscode.Forexample,Photoshopplug-insallowprogrammerstoeasilyextendthecapabilitiesofthePhotoshopapplicationwithouthavingaccesstoitssourcecode.Likewise,manyWebbrowsersuseplug-insthataddextrafeaturestotheapplicationorallowyoutomanipulatenewcontenttypesontheWeb.Manyprograms,includingCodeWarrior,makeuseofthisplug-inarchitecture.ThereareplentyofothertypesofprogramsyoucanwriteonceyoumasterCodeWarriorandtheprogramminginterfacesforyouroperatingsystem.Infact,onceyoucompletethiscourse,youcantakeothercoursesinwhichyouwilllearnmorein-depthmethodsofprogrammingyourcomputer.You'vechosenanexcellentplacetobeginyourjourney,however.Sositback,relax,andabsorbthelessonsinthiscourse,andyou'llbewellonyourwaytobecomingaCodeWarrior!AnIntroductiontotheCodeWarriorApplicationCodeWarriorisacomplexapplication.Ifyoureallywanttobenefitfromallofitsfeatures,youshouldtakethistimetogettoknowitsvariouscomponentsandthecapabilitiesthatwillbeavailabletoyou.ThisfirstlessonwillgiveyouabasicoverviewofhowtheCodeWarriorIDEissetup.(Thatacronymgetsthrownaroundalot,andit'sshortfor?IntegratedDevelopmentEnvironment.?)We'lltakealookatmenus,windows,andotheraspectsoftheprogram.FollowalongwiththeCodeWarriorIDEwhileyoureadthroughtheselessons.StartbylaunchingtheIDEapplication.IfyoufollowedthedefaultsfortheCodeWarriorsoftwareinstallation,therewillbeaniconthatrepresentsashortcuttotheprogram.Double-clickonittostarttheIDE.Iftheshortcuticonisabsent(thesethingshappen),youcantypicallyfindtheprogramatC:\ProgramFiles\Metrowerks\CodeWarrior\Bin\IDE.exe.ToolbarWhenyoulaunchtheCodeWarriorIDE,you'llnoticeatoolbarattachedtothemenuatthetopofyourscreen.Thistoolbar(Figure1-1)containsbuttonsthatareshortcutstofrequentlyusedmenuitems.You'lllearnhowtocustomizethistoolbar--andeventheentireIDE--inalaterlesson.Fornow,noticethatthistoolbarcanbeusedtoquicklyaccessfeatureswithintheIDE.Figure1-1:TheCodeWarriorIDEtoolbar.FileMenuThemenusintheCodeWarriorIDEaresetupinarelativelystandardmanner.TheFilemenucontainschoicesthatmanagethecareandfeedingoffiles.Ithasstandarditemsthatletyoucreate,open,save,andprintfiles.EditMenuTheEditmenuwillalsoseemfamiliarifyouuseotherWindowsapplications.You'llfindcommandsthatcut,copy,andpastetext,aswellasafewotheroptionstohelpprogrammersmoreeasilymanagesourcecodelayout.ThereisalsoaPreferencesitemintheEditmenuthatwe'lldiscusslaterinthislesson.ViewMenuTheViewmenu(Figure1-2)givesyouoptionstomanagewhichtoolbarsandotherwindowsaredisplayedintheCodeWarriorenvironment.Someofthesewindowsincludevariousspecialtywindows,suchastheWatchpointswindow,Expressionswindow,Processeswindow,andGlobalVariableswindow.Figure1-2:TheToolbarsubmenuoftheViewMenu.SearchMenuTheSearchmenu'scommandsallowyoutolocatesourcecodewithinasinglefile,orwithinthedirectoriesofyourharddisk.Youcanalsoeasilyreplacelargeblocksoftextorsearchyoursourcecodeforreferencestoothersourcecode.Thesetoolscanbeveryhandy,evenforsmallprojects.ProjectMenuToolsintheProjectmenuallowyoutomanageCodeWarriorprojects.Aprojectincludesallofthefilesthatmakeupaprogramyouarewriting,includingitsheaders,sourcecode,andlibraries.TheProjectwindowservesasacontainerforthesefiles.We'lldiscussthisinmoredepthinLesson2.DebugMenuWhenyoursourcecodedoesn'tdoexactlywhatyouwantitto(oryourcomputercrasheswhenyourunyourprogram),you'lldevelopacloserelationshipwiththeitemsontheDebugmenu.We'lldiscussdebugginginLesson5.WindowMenuTheWindowmenugivesyouthebasicoptionstomanagecascadingandtilingwindowsintheCodeWarriorenvironment.HelpMenuLastly,usetheHelpmenutogetonlinehelpwithjustaboutanyiteminCodeWarrior.Prettycoolsetup,huh?GettingtoKnowIDEPreferencesTheCodeWarriorIDEhasnumerouspreferencesthatyoucanusetocustomizeyourworkenvironment.Youmayonlywanttochangethetextcolor,oryoumightwanttogetmorepersonal,changinglotsofsettings.WhenyouselectPreferencesfromtheEditmenu,youarepresentedwiththeIDEPreferencesdialogbox(Figure1-3).There,you'llfindoptionsthatcontroltheappearanceandbehavioroftheCodeWarrioreditor,debugger,andlotsmore.Inthissection,we'lltakealookatthesepreferences.Figure1-3:ThePreferencesdialogbox.Aseachitemisdescribedbelow,followalonginyourowncopyofCodeWarrior,andcheckoutthevariousoptionsavailable.Youcangetadditionalhelpbyclickingonthequestionmark,thentheitemyou'reinterestedin.You'llseeatersedescriptionoftheselecteditem'spurpose.MoredetailedinformationisalsoavailablefromtheHelpmenu.TheGeneralPreferencesBuildSettings:?Choosewhethertosaveopen-sourcecodefilesbeforeperformingabuildandhowmuchmemorytousewhilebuilding.IDEExtras:?Varioussettingsthatdon'tbelonganywhereelse.Here'swhereyoucanhaveCodeWarriorinteroperatewithathird-partytexteditor.TheintegrationofeditorswiththeIDEisoftenlessthanperfect,butthislimitationmaybeoffsetbytheabilitytouseaneditorthatyouknowandlike.Plug-InSettings:?Usedbyplug-indeveloperstoassistinthedebuggingofplug-ins.ShieldedFolders:?Directorieslistedhereareskipped(ignored)duringprojectand/orfindandcompareoperations.Thiscanbeusefulifyouhavealargedirectoryof"data"filesinsideyourprojecthierarchyyetyoudonotwantthosefilestoslowdowncertainoperationsofCodeWarrior.SourceTrees:?ThisletsyouspecifydirectoriesotherthanthestandardonesCodeWarriorsearcheswhenitbuildsaprogram.EditorPreferencesEditorSettings:?VarioussettingstocustomizethewaytheEditordisplaysandmanagestextandwindows.FontsandTabs:?Textsize,font,tab,andotherdisplaysettingsfortheEditorwindows.TextColors:?Likethebrowserdisplay,youchoosethecolorinwhichcertainlanguageelements(suchascomments)appearintheEditorwindow.DebuggerPreferencesDisplaySettings:?Varioussettingstocustomizethedisplayofthedebugger.Windowing:?Howthedebuggermanagesitswindows(e.g.,hidinganyopeneditorwindows).GlobalSettings:?Varioussettingsthatcustomizehowthedebuggerworksonagloballevel,suchaswhethertolaunchaprogramwhenyouopenafilethatcontainstheprogram'sdebugginginformation.RemoteConnections:?AllowsdebuggingoverTCP/IP.YoucandebugsoftwareonacomputerontheothersideoftheEarth!JavaSettings/JavaDebugging:?Allowsyoutosetspecificjavaprogramminglanguageoptions,notcoveredinthiscourse.RADToolsLayoutEditor:?VarioussettingstocustomizetheuseofrapidapplicationdevelopmenttoolswithinCodeWarrior.Asyoucansee,therearenumeroussettingsandoptionsthatcanbeset.ClickingtheSavebuttonwillsaveanychangesyou'vemade.ClickingtheCloseboxforthePreferenceswindowwillcauseCodeWarriortoignoreanychangesyou'vemade.Goaheadandplaywithitalittlebeforeyouproceedtothenextlesson.MakesuretheDefaultTextFileFormat(intheEditorSettingspanel)remainssetforDOS.第二課??顯示和定制工程和目標(biāo)文件⑴Translatedfrom?CodeWarriorU.COM????本課將講述?CodeWarrior?操作文件的方式以及介紹它的工程(Project)窗口。什么是工程文件????為了使用?CodeWarrior?來創(chuàng)建一個(gè)應(yīng)用程序,你必須創(chuàng)建許多文件來構(gòu)成一個(gè)工程(Project)。該工程的設(shè)置和所有這些文件的指針都被存放在一個(gè)工程文件中。這些設(shè)置包括編譯和鏈接設(shè)置、源文件、庫文件以及它們之間用于產(chǎn)生最終程序的相互關(guān)系。你可以將這個(gè)工程文件看作該工程的大腦:它保存了所有文件相互依存的關(guān)系并知道如何將它們組合成為一個(gè)可用的應(yīng)用程序。工程窗口依次顯示了這些關(guān)于你的程序和該程序所包含的文件的信息,并允許你只需輕松點(diǎn)擊就可以修改這個(gè)工程。圖2-1顯示了工程窗口的外觀。圖?2-1:濕示工程信息的工程窗口圖示為空的情況????大多數(shù)組成你的程序的文件都是原始的文本文件。這些文件包含了你在?CodeWarrior?的編輯器中鍵入的源代碼。在某些情況下,你還將使用一些預(yù)編譯的源碼和頭文件。在進(jìn)行數(shù)學(xué)運(yùn)算和?I/O?操作時(shí),你還要使用到一些庫文件,比如Metrowerks?標(biāo)準(zhǔn)庫(MetrowerksStandardLibrary,MSL)????通常,你都是使用?C?或?C++?來編寫源代碼,但通過給?CodewWarrior?的集成開發(fā)環(huán)境加裝相應(yīng)的插件(plug-in),你也可以在?CodeWarrior?中使用其它語言來進(jìn)行編程。別忘了,CodeWarrior?可是一個(gè)可擴(kuò)展的集成開發(fā)環(huán)境。通過給它安裝一些插件,你就可以擴(kuò)展它的功能。比如說,加入有人開發(fā)了一種新的叫做?Z++?的編程語言,你就可以為CodeWarrior?創(chuàng)建一個(gè)相應(yīng)的插件使之能夠支持?Z++?語言,而且你還可以拿這個(gè)插件賣好多錢,讓所有使用CodeWarrior?編程的人都使上?Z++?語言。那該多好!:)????現(xiàn)在你知道了?CodeWarrior?是如何使用文件的了。下面我們來詳細(xì)地學(xué)習(xí)有關(guān)工程窗口的知識(shí)。工程窗口當(dāng)你啟動(dòng)?CodeWarrior?并打開或創(chuàng)建一個(gè)工程時(shí),工程窗口就會(huì)顯示出來。該窗口用于管理整個(gè)工程的所有文件以及這個(gè)工程將要產(chǎn)生的目標(biāo)(targets)文件。一個(gè)工程包含了足夠的信息來編譯一個(gè)或多個(gè)目標(biāo)文件。所謂的目標(biāo)(target)文件就是當(dāng)你編譯程序時(shí),由?CodeWariior?創(chuàng)建出來的(通常是)一個(gè)應(yīng)用程序或庫文件。一些程序可以編譯產(chǎn)生多個(gè)目標(biāo)文件。比如,你可以編寫一個(gè)程序來創(chuàng)建一個(gè)?DLL?和一個(gè)調(diào)用該?DLL?的主應(yīng)用程序。在?CodeWarrior?的工程中,你可以定義一個(gè)目標(biāo)來產(chǎn)生?DLL,定義另一個(gè)目標(biāo)來產(chǎn)生應(yīng)用程序。通過這種方式,你的工程只需編譯一次就可產(chǎn)生所有需要的目標(biāo)文件或片斷。圖?2-2?顯示了“HelloWorld”程序的工程窗口。圖?2-2:?HelloWorld程序的工程窗口其中顯示了所有包含于該程序中或用于編譯該程序的文件????你可以看到,在這個(gè)工程窗口中確實(shí)包含了一些項(xiàng)目。在窗口的頂端有三個(gè)標(biāo)簽(tab)頁:文件標(biāo)簽(如圖2-2顯示)、鏈接順序標(biāo)簽頁和目標(biāo)文件標(biāo)簽頁(后兩個(gè)標(biāo)簽頁將在后續(xù)課程中講述)。在這幾個(gè)標(biāo)簽頁的上方,有一個(gè)用于選擇要編譯的目標(biāo)文件的下拉菜單。在本例中,我們選擇的是?HelloWorld?工程的調(diào)試版本。在下拉菜單的右邊有幾個(gè)圖標(biāo),它們的存在允許你不必使用菜單命令就可以方便地編譯、鏈接和運(yùn)行這個(gè)工程。注意:?在某些版本的?CodeWarrior?中,鏈接標(biāo)簽被稱為段(segments)標(biāo)簽。有些人可能在某些?X86?的處理器上編程時(shí)使用的是分段(segmented)代碼。但使用?Windows?版的?CodeWarrior?工具時(shí)就不是這樣,這是產(chǎn)生的?X86?代碼使用的是"扁平的"(flat),或者叫做非分段的(unsegmented)?內(nèi)存空間。????顧名思義,文件標(biāo)簽頁列出了在工程中所有可能用到的文件。你可以通過創(chuàng)建一些組(用文件夾圖標(biāo)表示)來分門別類地管理這些文件,并可以幫助你方便地了解哪些文件將被使用。在本例中,我們將?C?程序(以.c為后綴名的文件)全都放到一個(gè)叫做?Source?的組中,同時(shí)將庫文件放到另一個(gè)組中,以便整潔明了地管理這些文件。????在?Sources?組中有一個(gè)?main.c?文件。因?yàn)槲覀冞€沒有編譯這個(gè)工程,所以在每個(gè)文件對(duì)應(yīng)的?Code?和?Data?欄中顯示數(shù)字的都是零。一旦我們編譯了這個(gè)工程,這些數(shù)字就將顯示出來,表示源碼轉(zhuǎn)換為機(jī)器代碼后實(shí)際的代碼量和數(shù)據(jù)量。可是,庫文件?ANSICX86.LIB?和?MWCRTL.LIB?后面顯示的是?n/a?。這表示索雖然這些文件被顯示在這里,但是它們并不是?HelloWorld?目標(biāo)文件的一部分。這兩個(gè)文件是用于不可調(diào)試(non-debugging)開發(fā)的,而本例不是這種情況。如果我們從菜單中修改本例的目標(biāo)文件為?Release(發(fā)布)?版本時(shí),這兩個(gè)文件就用得上了。這時(shí)這些文件后面的Code?和?Data?欄目就會(huì)顯示相應(yīng)的數(shù)值。注意?:?在?Data?和?Code?欄右端的?Target?欄目中的小子彈頭也是用來表示該文件是否被當(dāng)前編譯生成的目標(biāo)文件使用到。????再往右邊去,是?Debug?欄(用一個(gè)綠色的小蟲子表示),它是用于告訴你對(duì)應(yīng)的文件在編譯時(shí)是否要產(chǎn)生調(diào)試信息。我們將在第五課中詳細(xì)論述這部分內(nèi)容。最后,我們來看看在每一行最右端的彈出菜單,它是用于打開文件、更新源碼、打開包含的頭文件等等操作的快捷方式,具體是什么才作,要看它所代表的項(xiàng)目的類型而定。現(xiàn)在讓我們來編譯這個(gè)?HelloWorld?工程并看看編譯后的工程窗口的情況。我們從?Project?菜單中選擇?Make?命令來編譯該工程。這將更新所有需要編譯的文件并產(chǎn)生相應(yīng)的輸出文件——在本例中是?HelloWorld?這個(gè)應(yīng)用程序。圖?2-3:?編譯工程后的工程窗口的顯示情況從圖2-3中我們可以看到,工程窗口發(fā)生了一些變化。Code?和?Data?欄都顯示了當(dāng)前工程中對(duì)應(yīng)項(xiàng)的相應(yīng)的數(shù)字。如果你打算看看編譯前后存放這些文件的目錄的話,你會(huì)發(fā)現(xiàn)編譯后在該目錄下產(chǎn)生了一些新的文件,如圖2-4所示。圖?2-4:編譯后將在工程目錄中產(chǎn)生一些新的文件????在本例中,編譯工程后在工程目錄中產(chǎn)生了一個(gè)新的文件。這就是?X86?目標(biāo)文件輸出——生成一個(gè)叫做?Hell。Worldx86?的應(yīng)用程序。其它一些一直存在于這個(gè)目錄中的文件是:?.mcp?文件一工程文件本省,以及?.c?源文件一包含了應(yīng)用程序源碼的文件。HelloWorldData?目錄中還包含了由?CodwWarrior?生成的各種各樣的支持文件?,F(xiàn)在你還不必去關(guān)心這些文件。如果你正在編譯目標(biāo)文件的調(diào)試版本,你會(huì)看到更多的文件被產(chǎn)生出來,這些文件中可能包含著符號(hào)(symbolic)調(diào)試信息。集成開發(fā)環(huán)境的調(diào)試器使用這些符號(hào)信息來記錄在高層次源碼中的操作軌跡。我們將在第五課中詳細(xì)講述這方面內(nèi)容。????現(xiàn)在你已經(jīng)了解了這些文件是如何結(jié)合在一起被編譯生成一個(gè)目標(biāo)文件的。讓我們來運(yùn)行這個(gè)目標(biāo)文件并看看它的運(yùn)行結(jié)果是什么樣。你雙擊?HelloWorldx86?應(yīng)用程序,就會(huì)有如圖?2-5所示的結(jié)果顯示出來。圖?2-5:HelloWorld應(yīng)用程序的運(yùn)行結(jié)果你來試試看????總有一天,你自己也能編寫出象?HelloWorld?這樣充滿激情和意義深遠(yuǎn)的程序來。這是完全有可能的。只要你有決心努力工作,學(xué)完本課你就可以編寫這個(gè)程序了。下面我們給出該程序的源代碼:#include?voidmain(void){???intc;???printf("HelloWorldonWindows!\n");???c=getchar。;?}????就這么多!你沒想到會(huì)這么簡(jiǎn)單吧?你可以試試看將?”HelloWorldonWindows!"?這句話換成一句別的什么內(nèi)容。要不了多久,你就能自己編寫一些不僅能顯示文本而且還能執(zhí)行你指定的其它任務(wù)的應(yīng)用程序了。但在此之前,你還需要學(xué)習(xí)第四課,有關(guān)鏈接的知識(shí)。關(guān)于getchar。函數(shù)????那些有經(jīng)驗(yàn)的?C?程序員可能會(huì)問,上述代碼中使用的字符輸入函數(shù)?getchar。?用在這里是什么意思。通常地,當(dāng)一個(gè)應(yīng)用程序執(zhí)行完畢后,它就會(huì)終止,然后操作系統(tǒng)就會(huì)立即清除該應(yīng)用程序輸出。這樣,當(dāng)上述應(yīng)用程序顯示完“HelloWorldonWindows!”后,為了避免系統(tǒng)立即將該程序地輸出清除,我們?cè)诔绦蛑刑砑恿艘粋€(gè)?getchar°?函數(shù),使程序在此處暫停,直到有鍵盤輸入時(shí)整個(gè)程序會(huì)終止。這樣我們才有足夠的時(shí)間來看清楚該程序的輸出。????這是一個(gè)正常的操作,而不是一個(gè)?bug。實(shí)際上,CodeWarrior?也提供了一個(gè)適用于此處的庫函數(shù),這個(gè)庫函數(shù)中的C?控制臺(tái)?I/O?函數(shù)步不僅可以在程序顯示完畢后鎖定應(yīng)用程序,而且還可以讓你將輸出的文本信息存儲(chǔ)到一個(gè)文件中去。第一部分????第二部分附原文:DisplayingandCustomizingProjectsandTargetsInthissectionofthelesson,I'llintroduceyoutothewayCodeWarriorhandlesfiles

andgiveyouatouroftheProjectwindow.UnderstandingtheProjectFileTocreateprogramsinCodeWarrior,youwilluseanumberoffilesthatworktogethertoformaproject.Aproject'ssettingsandpointerstootherfilesarestoredwithina?projectfile.?Thesesettingsincludecompilerandlinkeroptions,sourcefiles,libraries,andinformationabouthowtheyinteractwithoneanothertobuildthefinalproduct一yourprogram.Fornow,justthinkoftheprojectfileasthebrainofyourproject:itkeepstrackofeverythingthatisgoingonandknowshowtocombinefilesandsettingsintoaworkingapplicationprogram.TheProjectwindowinturndisplaysthisinformationaboutyourprogramanditsfilesandallowsyoutomodifytheprojectbyjustpointingandclicking.Figure2-1showstheProjectwindow.Figure2-1:EachprojectyoucreateappearsintheProjectwindow.Thisoneisempty.Mostofthefilesthatmakeupyourprogramareordinarytextfiles.Thesefilescontainyoursourcecode.You'llcreatethembytypingthesourcecodeintotheCodeWarrioreditor.Insomecases,youwillalsouseprebuiltsourcecodeandheaderfiles.Therearealsolibraryfiles,suchastheMetrowerksStandardLibrary(MSL)whichprovidesvaluablefunctionsformathcalculationsandI/Ooperations.YoursourcecodewillusuallybewritteninCorC++,butcanalsobeinanyotherlanguagethatissupportedbyaCodeWarriorIDEplug-in.RecallthatCodeWarriorisanextensibleIDE.Inotherwords,byinserting(orwriting)aplug-in,youcanextendthecapabilitiesoftheCodeWarriorIDE.Forexample,ifsomeonedevelopsanewprogramminglanguage,sayZ++,youcouldcreateaplug-intosupportthatlanguageandsellitforazillionbucks,andthenanyoneusingtheCodeWarriorIDEcouldprograminZ++.Neat,huh?NowthatyouunderstandhowCodeWarriorusesfiles,let'stakeacloserlookattheProjectwindow.TheProjectWindowWhenyoulaunchCodeWarriorandopenorcreateaproject,aProjectwindowgreetsyou.Torecap,itallowsyoutomanagetheproject,allofitsfiles,andthe?targets?thatitbuilds.Aprojectcontainsalloftheinformationnecessarytobuildoneormoretargets.AtargetisthefilethatCodeWarriorcreateswhenyoubuildyourprogram-usuallyanapplicationorlibrary.Someprojectsbuildmultipletargets.Forexample,youmaywriteaprogramthathasaDLL,aswellasthemainapplicationthatcallsit.IntheCodeWarriorproject,youcandefineonetargettogeneratetheDLL,andanothertargettogeneratetheapplication.Inthisway,yourprojectcanbuildallthenecessarytargets,orpieces,inonefellswoop.Figure2-2showstheProjectwindowforaprogramcalledHelloWorld.igure2-2:TheProjectwindowforaprogramcalledHelloWorldlistsallofthefilesthatareincludedintheprogramorthatareneededtobuildit.YoucanseethattheProjectwindowcontainsquiteafewitems.Atthetoparethreetabs:theFilestab(displayedinFigure2-2),theLinkOrdertab,andtheTargetstab(bothdiscussedlaterinthislesson).Abovethetabsisapull-downmenuthatallowsyoutochoosewhichtargettobuild.Inthiscase,wehavechosentheDebugversionoftheHelloWorldproject.Theiconstotherightofthispull-downmenuallowustoeasilycompile,link,andruntheprojectwithouthavingtousemenucommands.Note:?TheLinkOrdertabiscalledtheSegmentstabinsomeversionsofCodeWarrior.Someofyoumighthaveprogrammedcertainx86processorsusingsegmentedcode.ThisisnotthecasewiththeWindowsCodeWarriortools.Theygeneratex86codethatusesa"flat,"orunsegmented,memoryspace.Asitsnameimplies,theFilestablistsallofthefilesthatcouldpossiblybeusedintheproject.Youcancreategroups(representedbythefoldericon)inthewindowtohelpmanagethefileshierarchicallyandmakeiteasiertokeeptrackofwhichfilesarebeingused.Inourcase,weplaceourClanguagesourcecodefiles(indicatedbythe.cextension)inagroupcalledSources.We'veorganizedlibrariesintoothergroupstokeepthingstidy.TheSourcesgroupforourexampleholdsthemain.cfile.Sincewehaveyettobuildthisproject,thenumbersintheCodeandDatacolumnsareallsettozero.Whenwebuildtheprojectforthefirsttime,thesenumberswillreflecttheactualamountofcodeanddatathecompilercreateswhenittranslatesthesourcecodeintomachinelanguage.However,thelibraryfilesANSICX86.LIBandMWCRTL.LIBhaven/anexttothem.Thisindicatesthateventhoughthesefilesarelisted,theyarenotusedaspartoftheHelloWorldtarget.That'sbecausethesetwolibrariesareusedfornon-debuggingdevelopment,whichisnotapplicableforthistarget.IfweweretoswitchtargetsbypickingtheReleaseversionofHelloWorldfromthemenu,thesecolumnswouldchangetoreflecttheuseoftheseotherlibraries.Note?:ThesmallbulletintheTargetcolumntotherightoftheDatacolumnalsoindicateswhetherornotthefileisbeingusedbythecurrenttarget.OthercolumnsinthemainwindowincludetheDebugcolumn,totheright(seethelittlegreenbug?),whichtellsyouwhetherthisfileiscurrentlysettogeneratedebuginformationwhenitiscompiled.WewilldiscussthisinmoredetailinLesson5.Andlastly,thepop-upmenuatthefarrightofeachrowactsasashortcutthatallowsyoutoquicklyopenfilesand/orupdatesourcesforcompilation,openincludedheaderfiles,etc.,dependingonthetypeofitemitrepresents.Let'sbuildtheHelloWorldprojectandseewhatthewindowlookslikeafteritisbuilt.Tobuildthisproject,selectMakefromtheProjectmenu.Thiswillupdateallfilesthatneedtobebuiltandwillproducetheoutputfile--inthiscase,theHelloWorldapplication.

Figure2-3:Whenyoubuildaproject,theCodeandDataitemsforeachcolumnarefilledin.NoticeinFigure2-3thatthewindowhaschangedabit.TheCodeandDatacolumnsnowcontainnumbersfortheitemsthatareinthecurrentproject.Ifyouweretolookatabeforeandafterscreenshotofthefolderonyourharddiskwheretheseitemsarestored,youwouldseethatsomenewfileshavebeengenerated.Let'stakeaquicklookatthoseitemsinFigure2-4.Figure2-4:Buildingaprojectgeneratesnewfileswithinyourprojectfolder.Noticeinourexamplethatthereisanewfileintheprojectdirectory.Thisisthex86target'soutput--theapplicationcalledHelloWorldx86.Otherfilesinthisdirectorythatexistallofthetimearethe.mcpfile--theprojectfileitself--andthe.csourcefile,whichcontainsthesourcecodefortheapplication.TheHelloWorldDatadirectorycontainsvariousothersupportfilesgeneratedbyCodeWarrior.Youneednotbeconcernedwiththeseitemsatthistime.Ifyouarebuildingadebugversionofthetarget,you'llseeevenmorefiles,whichcancontainsymbolicdebugginginformation.TheIDE'sdebuggerusesthesymbolicinformationtohelpitpresenttrackingoperationsinhigh-levelsourcecode.ThesedetailsarediscussedlaterinLesson5.Nowthatyouunderstandhowthefilesworktogethertobuildatarget,let'srunthetargetandseewhatitlookslike.Whenyoudouble-clicktheHelloWorldx86application,thefollowing(Figure2-5)appearsonthescreen.Figure2-5:WhenyouruntheHelloWorldprogram,awindowcontainingthewords"HelloWorld"appearsonscreen.PuttingItintoPlaySomeday,youtoomaycreatesomethingaslyricalandprofoundasHelloWorld.Possibly,withhardworkanddetermination,youcandothisbytheendoftheday.Thesourcecodetomakethisworkisasfollows:vp>#include<stdio.h>Vp>voidmain(void){intc;printf("HelloWorldonWindows!\n");c=getchar();}That'sit!Whoknewitcouldbesoeasy?Goon,youknowyouwanttotryit,butwithsomesortofprofoundstatementinsteadof"HelloWorldonWindows!"Soonyou'llbewritingyourownapplicationsthatnotonlycandisplaytextbutcanalsoperformothertasksforyou.Beforeyouknowit,you'llbecustomizingAIBOdogs!That'sLesson4.Well,okay,notreally.Lesson4isLinking.What'sThatOtherFunctionDoingThere?ThosealreadyseasonedintheClanguagemightbewonderingwhatthecharacterinput?function,getchar。,isdoinghere.Typically,whenanapplicationcompletesitsjob,itterminates,andtheOScleansupaftertheprogram.ThismeanstheHelloWorldwindowdisappearsmomentsaftertheapplicationfinishesdrawingthephrase"HelloWorldonWindows!"Sotha

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論