




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
CodeWarrior使用教程第一课认识CodeWarriorTranslatedfrom?CodeWarriorU.COMCodeWarrior?能做些什么?????当你知道自己能写更好的程序时,你一定不会再使用别人开发的应用程序。但是常常会发生这种情况,就是当你写了无数行代码后,却找不到使得整个程序出错的那一行代码,导致根本没法编译和链接整个程序。这可能更令人灰心丧气。????本文将告诉你如何使用?CodeWarrior?这一工具解决上述问题。????从现在开始,我们将集中精力学习如何在?CodeWarrior?中使用?C/C++?进行编程。为了学习本课程,你必须已经能够比较熟练地使用上述两种语言之一。CodeWarrior?也可以支持?Java?开发,但那是另一门课程的内容。本课程仅限于在?Windows?平台上使用?CodeWarrior?进行的开发。一旦你精通了?CodeWarrior?编程后,你可以试试在其它平台上使用?CodeWarrior。本文中讨论过的大部分内容都可以应用到开发?Mac?应用程序中。???CodeWarrior?能够自动地检查代码中的明显错误,它通过一个集成的调试器和编辑器来扫描你的代码,以找到并减少明显的错误,然后编译并链接程序以便计算机能够理解并执行你的程序。你所使用过的每个应用程序都经过了使用象?CodeWorrior?这样的开发工具进行编码、编译、编辑、链接和调试的过程。现在你在我们的指导下,自己也可以去做这些工作了。????你可以使用?CodeWarrior?来编写你能够想象得到的任何一种类型的程序。如果你是一个初学者,你可以选择编写一个应用程序(比如一个可执行程序),比如象微软公司的文本编辑器?WordPad?这样的应用程序。????应用程序可能是最容易编写的程序了,而那些庞大的商业软件,比如象?AdobePhotoshop,MicrosoftWord?以及?CodeWarrior?软件都是极其复杂的。其它类型的程序指的是控制面板(controlpanels),动态链接库(dynamiclinkedlibraries,DLLs)?和插件(plug-ins)。我们先来简单的讨论一下这些类型的程序。????在?Windows冲,控制面板程序是一些(通常比较小的)存放在控制面板目录下的程序,可以在开始菜单的控制面板项中看到它们。控制面板实际上是设置系统功能的一个简单界面,比如可以在控制面板中完成诸如设置音量和鼠标移动速度这样一些参数。????动态链接库?(DLLs)?提供了一些很有用的被系统和应用程序共享的函数。通常它们都是没有用户界面的。????插件?(Plug-ins)?有点类似于?DLLs,插件也是可供其它软件使用的小程序,但插件只能被特定的软件使用。比如说,Photoshop?的插件允许程序员方便地扩展?Photoshop?的功能,而不需要去修改它的源代码。同样的,许多?Web?浏览器也使用插件来增加功能,或者为了让你能够看到页面上的新的内容类型。实际上,有许多程序,包括?CodeWarrior,都使用这种插件结构。????一旦你掌握了?CodeWarior?和你所使用的操作系统的编程接口时,你可以编写许多其它类型的程序。实际上,本课程也是你深入学习其它编程方法的基础课程。你已经找到了一个最优秀的地方开始你的编程之旅。好,现在请坐好,放松,去吸取这门课程的精华吧,你将踏上一条成为一个编程武士的道路!CodeWarrior?入门???CodeWarrior?是一个复杂的应用程序,你必须花点时间来了解它的各种各样的组件和功能。第一课将讲述CodeWarriorIDE?的安装。我们将学习菜单、窗口和其它的一些方面。建议你最好一边学习本课程,一边学习使用?CodeWarrior?的集成开发环境。我们从运行?CodeWarrior?开始,如果你按照默认方式安装的CodeWarrior?软件,那么在?Windows?的桌面上将会有一个该软件的快捷方式图标。双击该图标启动CodeWarrior?的集成开发环境。如果在?Windows?桌面上没有这个快捷图标(这种情况经常发生),你可以在C:\ProgramFiles\Metrowerks\CodeWarrior\Bin?中找到?IDE.exe?文件,然后运行它。工具条启动?CodeWarrior?后,你将会看到,在屏幕上方的菜单下面有一个工具条。这个工具条(见图1-1)包含了一些常用菜单项的快捷方式。在后面的章节中,你将学到如何设置这个工具条,甚至是整个?IDE?环境。现在,你应记住,这个工具条用于快捷使用?IDE?中的功能。图?1-1:CodeWarriorIDE的工具条文件菜单???CodeWarriorIDE?的菜单是按照标准方式设置的。其中的文件菜单用于处理和文件相关的一些操作,比如创建、打开、保存和打印等等。编辑菜单???CodeWarrior?的编辑菜单和其它的?Windows?应用程序也很相像。其中包括了剪切、复制和粘贴等操作,以及其它一些使得程序员能够更方便地管理源码版面布局的选项。在编辑菜单中还有一个?Preferences?项,我们在这一课的后面将提到它。查看菜单查看菜单(图1-2)用于安排工具条和其它窗口在?CodeWarrior?环境中如何显示的选项。所谓的“其它窗口”包括许多特殊的窗口,比如观察点(Watchpoints)窗口,表达式(Expressions)窗口,过程(Processes)窗口和全局变量(GlobalVariables)窗口等。图?1-2:?查看菜单中的工具条子菜单查找菜单????查找菜单用于在单个文件或硬盘的目录中查找指定的代码。你可以使用它来方便地替换文本块或在你的代码中搜索指定的项目。即使是在小工程中使用这个工具也非常方便。工程菜单????工程菜单中的工具用于管理?CodeWarrior?工程。一个工程包括组成你正在编写的程序的所有的文件,包括头文件、源代码和库文件。工程窗口显示了所有这些文件的名称。我们将在第二课中深入讨论这部分内容。调试菜单????这是在编制程序中最常用到的工具。我们将在第五课中详细介绍它的使用方法。窗口菜单????用于在?CodeWarrior?环境管理窗口显示方式的菜单。帮助菜单????通过帮助菜单可以到网上寻求关于PCodeWarrior?任何问题的在线解答。够酷的吧?了解?CodeWarrior?集成开发环境的设置???CodeWarriorIDE?提供了许多设置以便让你定制你的工作环境。当你选择了编辑菜单中的?Preferences?项时,你将会看到一个设置对话框(如图1-3)o在该对话框中,有控制?CodeWarrior?编辑器、调试器和其它许多功能的界面和行为的选项。在这一节中,我们将学习这些设置的使用。图?1-3:?<置对话框????你可以在自己的PCodeWarrior?中试试上述这些设置项。你可以先点击问号标志,然后点击你感兴趣的项目,就可以得到一个有关该项目的用途的简短介绍,也可以从帮助菜单中得到更详细的信息。通用设置编译设置(BuildSettings):?选择是否在执行编译之前保存已打开的源文件,以及有多少内存被用于编译工作;IDE?之外(IDEExtras):?几个独立的设置。比如指定PCodeWarrior?是否使用一个第三方的文本编辑器——因为集成的编辑器并不是很完美,这可以通过指定一个你惯用的编辑器来替代它;插件设置(Plug-InSettings):?供插件开发商调试他们的插件;隐藏文件夹(ShieldedFolders):?^这里指定的文件夹在工程设计期间,或执行查找和比较操作期间,将要被忽略掉。如果在你的工程级有一个巨大的“数据”文件目录,而你又不想让这些文件降低CodeWarrior?的操作速度时,这个设置就很管用了;资料树(SourceTrees):?用于指定?CodeWarrior?在编译程序时用不着的目录。编辑器设置编辑器设置(EditorSettings):?几个用于定制编辑器显示、管理文本和窗口的设置项;字体和制表符(FontsandTabs):?设置编辑器中的文本大小、字体、制表符和其它显示设置;文本颜色(TextColors):?用于指定特定语言元素(比如程序的注释)在编辑窗口中的显示的颜色。调试器设置显示设置(DisplaySettings):?几个用于定制调试器显示的设置项;视窗化(Windowing):?设定调试器如何管理它的窗口(比如隐藏所有打开的编辑器窗口);全局设置(GlobalSettings):?几个用于定制调试器在全局层次如何工作的设置。比如当一个包含了程序调试信息的文件被打开时,是否启动这个程序;远程连接(RemoteConnections):?允许通过PTCP/IP?进行远程调试。这样,你就可以在地球的另一边调试你的软件了;Java?设置/Java?调试(JavaSettings/JavaDebugging):?允许你设置特定的?Java?编程语言选项。本课程不涉及这部分内容。RAD?工具Layout?编辑器:?几个用于在?CodeWmior?中定制快速应用程序开发工具的使用的设置。????正如你所见到的,CodeWarrior?有许多设置项和选项。设置完后点击“Save”按钮保存你所作的修改,点击“Close”按钮将忽略你所作的所有修改。在进入下一节课之前,多练习几次。最后请确认“默认的文本文件格式(DefaultTextFileFormat)”(在编辑器设置面板中)保持为?DOS?设置。(待续)附原文: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.第二课??显示和定制工程和目标文件⑴Translatedfrom?CodeWarriorU.COM????本课将讲述?CodeWarrior?操作文件的方式以及介绍它的工程(Project)窗口。什么是工程文件????为了使用?CodeWarrior?来创建一个应用程序,你必须创建许多文件来构成一个工程(Project)。该工程的设置和所有这些文件的指针都被存放在一个工程文件中。这些设置包括编译和链接设置、源文件、库文件以及它们之间用于产生最终程序的相互关系。你可以将这个工程文件看作该工程的大脑:它保存了所有文件相互依存的关系并知道如何将它们组合成为一个可用的应用程序。工程窗口依次显示了这些关于你的程序和该程序所包含的文件的信息,并允许你只需轻松点击就可以修改这个工程。图2-1显示了工程窗口的外观。图?2-1:湿示工程信息的工程窗口图示为空的情况????大多数组成你的程序的文件都是原始的文本文件。这些文件包含了你在?CodeWarrior?的编辑器中键入的源代码。在某些情况下,你还将使用一些预编译的源码和头文件。在进行数学运算和?I/O?操作时,你还要使用到一些库文件,比如Metrowerks?标准库(MetrowerksStandardLibrary,MSL)????通常,你都是使用?C?或?C++?来编写源代码,但通过给?CodewWarrior?的集成开发环境加装相应的插件(plug-in),你也可以在?CodeWarrior?中使用其它语言来进行编程。别忘了,CodeWarrior?可是一个可扩展的集成开发环境。通过给它安装一些插件,你就可以扩展它的功能。比如说,加入有人开发了一种新的叫做?Z++?的编程语言,你就可以为CodeWarrior?创建一个相应的插件使之能够支持?Z++?语言,而且你还可以拿这个插件卖好多钱,让所有使用CodeWarrior?编程的人都使上?Z++?语言。那该多好!:)????现在你知道了?CodeWarrior?是如何使用文件的了。下面我们来详细地学习有关工程窗口的知识。工程窗口当你启动?CodeWarrior?并打开或创建一个工程时,工程窗口就会显示出来。该窗口用于管理整个工程的所有文件以及这个工程将要产生的目标(targets)文件。一个工程包含了足够的信息来编译一个或多个目标文件。所谓的目标(target)文件就是当你编译程序时,由?CodeWariior?创建出来的(通常是)一个应用程序或库文件。一些程序可以编译产生多个目标文件。比如,你可以编写一个程序来创建一个?DLL?和一个调用该?DLL?的主应用程序。在?CodeWarrior?的工程中,你可以定义一个目标来产生?DLL,定义另一个目标来产生应用程序。通过这种方式,你的工程只需编译一次就可产生所有需要的目标文件或片断。图?2-2?显示了“HelloWorld”程序的工程窗口。图?2-2:?HelloWorld程序的工程窗口其中显示了所有包含于该程序中或用于编译该程序的文件????你可以看到,在这个工程窗口中确实包含了一些项目。在窗口的顶端有三个标签(tab)页:文件标签(如图2-2显示)、链接顺序标签页和目标文件标签页(后两个标签页将在后续课程中讲述)。在这几个标签页的上方,有一个用于选择要编译的目标文件的下拉菜单。在本例中,我们选择的是?HelloWorld?工程的调试版本。在下拉菜单的右边有几个图标,它们的存在允许你不必使用菜单命令就可以方便地编译、链接和运行这个工程。注意:?在某些版本的?CodeWarrior?中,链接标签被称为段(segments)标签。有些人可能在某些?X86?的处理器上编程时使用的是分段(segmented)代码。但使用?Windows?版的?CodeWarrior?工具时就不是这样,这是产生的?X86?代码使用的是"扁平的"(flat),或者叫做非分段的(unsegmented)?内存空间。????顾名思义,文件标签页列出了在工程中所有可能用到的文件。你可以通过创建一些组(用文件夹图标表示)来分门别类地管理这些文件,并可以帮助你方便地了解哪些文件将被使用。在本例中,我们将?C?程序(以.c为后缀名的文件)全都放到一个叫做?Source?的组中,同时将库文件放到另一个组中,以便整洁明了地管理这些文件。????在?Sources?组中有一个?main.c?文件。因为我们还没有编译这个工程,所以在每个文件对应的?Code?和?Data?栏中显示数字的都是零。一旦我们编译了这个工程,这些数字就将显示出来,表示源码转换为机器代码后实际的代码量和数据量。可是,库文件?ANSICX86.LIB?和?MWCRTL.LIB?后面显示的是?n/a?。这表示索虽然这些文件被显示在这里,但是它们并不是?HelloWorld?目标文件的一部分。这两个文件是用于不可调试(non-debugging)开发的,而本例不是这种情况。如果我们从菜单中修改本例的目标文件为?Release(发布)?版本时,这两个文件就用得上了。这时这些文件后面的Code?和?Data?栏目就会显示相应的数值。注意?:?在?Data?和?Code?栏右端的?Target?栏目中的小子弹头也是用来表示该文件是否被当前编译生成的目标文件使用到。????再往右边去,是?Debug?栏(用一个绿色的小虫子表示),它是用于告诉你对应的文件在编译时是否要产生调试信息。我们将在第五课中详细论述这部分内容。最后,我们来看看在每一行最右端的弹出菜单,它是用于打开文件、更新源码、打开包含的头文件等等操作的快捷方式,具体是什么才作,要看它所代表的项目的类型而定。现在让我们来编译这个?HelloWorld?工程并看看编译后的工程窗口的情况。我们从?Project?菜单中选择?Make?命令来编译该工程。这将更新所有需要编译的文件并产生相应的输出文件——在本例中是?HelloWorld?这个应用程序。图?2-3:?编译工程后的工程窗口的显示情况从图2-3中我们可以看到,工程窗口发生了一些变化。Code?和?Data?栏都显示了当前工程中对应项的相应的数字。如果你打算看看编译前后存放这些文件的目录的话,你会发现编译后在该目录下产生了一些新的文件,如图2-4所示。图?2-4:编译后将在工程目录中产生一些新的文件????在本例中,编译工程后在工程目录中产生了一个新的文件。这就是?X86?目标文件输出——生成一个叫做?Hell。Worldx86?的应用程序。其它一些一直存在于这个目录中的文件是:?.mcp?文件一工程文件本省,以及?.c?源文件一包含了应用程序源码的文件。HelloWorldData?目录中还包含了由?CodwWarrior?生成的各种各样的支持文件。现在你还不必去关心这些文件。如果你正在编译目标文件的调试版本,你会看到更多的文件被产生出来,这些文件中可能包含着符号(symbolic)调试信息。集成开发环境的调试器使用这些符号信息来记录在高层次源码中的操作轨迹。我们将在第五课中详细讲述这方面内容。????现在你已经了解了这些文件是如何结合在一起被编译生成一个目标文件的。让我们来运行这个目标文件并看看它的运行结果是什么样。你双击?HelloWorldx86?应用程序,就会有如图?2-5所示的结果显示出来。图?2-5:HelloWorld应用程序的运行结果你来试试看????总有一天,你自己也能编写出象?HelloWorld?这样充满激情和意义深远的程序来。这是完全有可能的。只要你有决心努力工作,学完本课你就可以编写这个程序了。下面我们给出该程序的源代码:#include?voidmain(void){???intc;???printf("HelloWorldonWindows!\n");???c=getchar。;?}????就这么多!你没想到会这么简单吧?你可以试试看将?”HelloWorldonWindows!"?这句话换成一句别的什么内容。要不了多久,你就能自己编写一些不仅能显示文本而且还能执行你指定的其它任务的应用程序了。但在此之前,你还需要学习第四课,有关链接的知识。关于getchar。函数????那些有经验的?C?程序员可能会问,上述代码中使用的字符输入函数?getchar。?用在这里是什么意思。通常地,当一个应用程序执行完毕后,它就会终止,然后操作系统就会立即清除该应用程序输出。这样,当上述应用程序显示完“HelloWorldonWindows!”后,为了避免系统立即将该程序地输出清除,我们在程序中添加了一个?getchar°?函数,使程序在此处暂停,直到有键盘输入时整个程序会终止。这样我们才有足够的时间来看清楚该程序的输出。????这是一个正常的操作,而不是一个?bug。实际上,CodeWarrior?也提供了一个适用于此处的库函数,这个库函数中的C?控制台?I/O?函数步不仅可以在程序显示完毕后锁定应用程序,而且还可以让你将输出的文本信息存储到一个文件中去。第一部分????第二部分附原文: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等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 船舶租赁合同标准示范文本
- 签订的办公楼租赁与物业管理合同
- 维护网络安全应该怎做
- 国际物流模拟题与参考答案
- 电工基础复习题(附参考答案)
- 旅游经济学试题库含答案
- 中级制图员考试模拟题(附答案)
- 新上任管理岗位指南
- 场地租赁合同范例
- 采购供应合同集合
- 颅骨骨折患者的护理查房
- 防止校园欺凌安全教育课件
- 北师大版小学六年级数学下册期第三单元检测试卷2(附答案)
- 江苏省徐州市铜山区2022-2023学年高二下学期期中地理试题(解析版)
- 微观经济学复习题
- 曲臂式高空作业车施工方案
- 疏水阀CS49H中英文说明书
- 检验科知识习题库(含答案)
- 药物开发过程中的晶型研究详解演示文稿
- 广东省2023年九年级中考备考语文专题复习:现代文阅读题(二)(含解析)
- 砂子表观密度测定试验(容量瓶法)
评论
0/150
提交评论