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

下載本文檔

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

文檔簡(jiǎn)介

1、實(shí)用文檔CodeWarrior 使用教程第一課認(rèn)識(shí)CodeWarriorTranslated from CodeWarriorU.COMCodeWarrior 能做些什么?當(dāng)你知道自己能寫(xiě)更好的程序時(shí),你一定不會(huì)再使用別人開(kāi)發(fā)的應(yīng)用程序。但是常常會(huì)發(fā)生這種情況, 就是當(dāng)你寫(xiě)了無(wú)數(shù)行代碼后,卻找不到使得整個(gè)程序出錯(cuò)的那一行代碼,導(dǎo)致根本沒(méi)法編譯和鏈接整個(gè)程序。這 可能更令人灰心喪氣。本文將告訴你如何使用CodeWarrior這一工具解決上述問(wèn)題。從現(xiàn)在開(kāi)始,我們將集中精力學(xué)習(xí)如何在CodeWarrior 中使用 C/C+進(jìn)行編程。為了學(xué)習(xí)本課程,你必須已經(jīng)能夠比較熟練地使用上述兩種語(yǔ)言之一。Co

2、deWarrior 也可以支持 Java 開(kāi)發(fā),但那是另一門(mén)課程的內(nèi)容。本課程僅限于在Windows平臺(tái)上使用CodeWarrior進(jìn)行的開(kāi)發(fā)。一旦你精通了 CodeWarrior編程后,你可以試試在其它平臺(tái)上使用CodeWarrior。本文中討論過(guò)的大部分內(nèi)容都可以應(yīng)用到開(kāi)發(fā)Mac應(yīng)用程序中。CodeWarrior能夠自動(dòng)地檢查代碼中的明顯錯(cuò)誤,它通過(guò)一個(gè)集成的調(diào)試器和編輯器來(lái)掃描你的代碼,以找到并減少明顯的錯(cuò)誤,然后編譯并鏈接程序以便計(jì)算機(jī)能夠理解并執(zhí)行你的程序。你所使用過(guò)的每個(gè)應(yīng)用程 序都經(jīng)過(guò)了使用象CodeWorrior這樣的開(kāi)發(fā)工具進(jìn)行編碼、編譯、編輯、鏈接和調(diào)試的過(guò)程。現(xiàn)在你在我們

3、的指導(dǎo)下,自己也可以去做這些工作了。你可以使用CodeWarrior來(lái)編寫(xiě)你能夠想象得到的任何一種類(lèi)型的程序。如果你是一個(gè)初學(xué)者,你可以選擇編寫(xiě)一個(gè)應(yīng)用程序(比如一個(gè)可執(zhí)行程序),比如象微軟公司的文本編輯器WordPad這樣的應(yīng)用程序。應(yīng)用程序可能是最容易編寫(xiě)的程序了,而那些龐大的商業(yè)軟件,比如象Adobe Photoshop , MicrosoftWord 以及 CodeWarrior 軟件都是極其復(fù)雜的。其它類(lèi)型的程序指的是控制面板(control panels) ,動(dòng)態(tài)鏈接庫(kù)(dynamic linked libraries , DLLs) 和插件(plug-ins)。我們先來(lái)簡(jiǎn)單的討論

4、一下這些類(lèi)型的程序。在 Windows中,控制面板程序是一些 (通常比較小的)存放在控制面板目錄下的程序,可以在開(kāi)始菜 單的控制面板項(xiàng)中看到它們??刂泼姘鍖?shí)際上是設(shè)置系統(tǒng)功能的一個(gè)簡(jiǎn)單界面,比如可以在控制面板中完成諸如 設(shè)置音量和鼠標(biāo)移動(dòng)速度這樣一些參數(shù)。動(dòng)態(tài)鏈接庫(kù) (DLLs) 提供了一些很有用的被系統(tǒng)和應(yīng)用程序共享的函數(shù)。通常它們都是沒(méi)有用戶(hù)界面的。插件(Plug-ins)有點(diǎn)類(lèi)似于DLLs,插件也是可供其它軟件使用的小程序,但插件只能被特定的軟件使用。比如說(shuō),Photoshop的插件允許程序員方便地?cái)U(kuò)展Photoshop 的功能,而不需要去修改它的源代碼。同樣的,許多Web瀏覽器也使用插

5、件來(lái)增加功能,或者為了讓你能夠看到頁(yè)面上的新的內(nèi)容類(lèi)型。實(shí)際上,有許多程序,包括 CodeWarrior ,都使用這種插件結(jié)構(gòu)。一旦你掌握了CodeWarior和你所使用的操作系統(tǒng)的編程接口時(shí),你可以編寫(xiě)許多其它類(lèi)型的程序。實(shí)際上,本課程也是你深入學(xué)習(xí)其它編程方法的基礎(chǔ)課程。你已經(jīng)找到了一個(gè)最優(yōu)秀的地方開(kāi)始你的編程之旅。好,現(xiàn)在請(qǐng)坐好,放松,去吸取這門(mén)課程的精華吧,你將踏上一條成為一個(gè)編程武士的道路!CodeWarrior 入門(mén)CodeWarrior是一個(gè)復(fù)雜的應(yīng)用程序,你必須花點(diǎn)時(shí)間來(lái)了解它的各種各樣的組件和功能。第一課將講述CodeWarrior IDE的安裝。我們將學(xué)習(xí)菜單、窗口和其它的

6、一些方面。建議你最好一邊學(xué)習(xí)本課程,一邊學(xué)習(xí)使用 CodeWarrior的集成開(kāi)發(fā)環(huán)境。我們從運(yùn)行CodeWarrior 開(kāi)始,如果你按照默認(rèn)方式安裝的CodeWarrior 軟件,那么在 Windows的桌面上將會(huì)有一個(gè)該軟件的快捷方式圖標(biāo)。雙擊該圖標(biāo)啟動(dòng) CodeWarrior的集成開(kāi)發(fā)環(huán)境。如果在 Windows桌面上沒(méi)有這個(gè)快捷圖標(biāo)(這種情況經(jīng)常發(fā)生),你可以在C:Program FilesMetrowerksCodeWarriorBin中找到 IDE.exe 文件,然后運(yùn)行它。工具條啟動(dòng) CodeWarrior 后,你將會(huì)看到,在屏幕上方的菜單下面有一個(gè)工具條。這個(gè)工具條(見(jiàn)圖1-1

7、)包含了一些常用菜單項(xiàng)的快捷方式。在后面的章節(jié)中,你將學(xué)到如何設(shè)置這個(gè)工具條,甚至是整個(gè)IDE 環(huán)境?,F(xiàn)在,你應(yīng)記住,這個(gè)工具條用于快捷使用IDE中的功能。圖 1-1: CodeWarrior IDE 的工具條文件菜單CodeWarrior IDE 的菜單是按照標(biāo)準(zhǔn)方式設(shè)置的。其中的文件菜單用于處理和文件相關(guān)的一些操作,比 如創(chuàng)建、打開(kāi)、保存和打印等等。編輯菜單CodeWarrior的編輯菜單和其它的Windows應(yīng)用程序也很相像。其中包括了剪切、復(fù)制和粘貼等操作,以及其它一些使得程序員能夠更方便地管理源碼版面布局的選項(xiàng)。在編輯菜單中還有一 個(gè) Preferences 項(xiàng),我們?cè)谶@一課的后面將

8、提到它。查看菜單查看菜單(圖1-2)用于安排工具條和其它窗口在CodeWarrior環(huán)境中如何顯示的選項(xiàng)。所謂的“其它窗口”包括許多特殊的窗口,比如觀察點(diǎn) (Watchpoints) 窗口,表達(dá)式(Expressions) 窗口,過(guò)程(Processes)窗口和全 局變量(Global Variables) 窗口等。圖1-2:查看菜單中的工具條子菜單查找菜單查找菜單用于在單個(gè)文件或硬盤(pán)的目錄中查找指定的代碼。你可以使用它來(lái)方便地替換文本塊或在你的代碼中搜索指定的項(xiàng)目。即使是在小工程中使用這個(gè)工具也非常方便。工程菜單工程菜單中的工具用于管理CodeWarrior工程。一個(gè)工程包括組成你正在編寫(xiě)的

9、程序的所有的文件,包括頭文件、源代碼和庫(kù)文件。工程窗口顯示了所有這些文件的名稱(chēng)。我們將在第二課中深入討論這部分內(nèi)容。調(diào)試菜單這是在編制程序中最常用到的工具。我們將在第五課中詳細(xì)介紹它的使用方法。窗口菜單用于在 CodeWarrior環(huán)境管理窗口顯示方式的菜單。幫助菜單通過(guò)幫助菜單可以到網(wǎng)上尋求關(guān)于CodeWarrior 任何問(wèn)題的在線解答。夠酷的吧?了解 CodeWarrior集成開(kāi)發(fā)環(huán)境的設(shè)置CodeWarrior IDE提供了許多設(shè)置以便讓你定制你的工作環(huán)境。當(dāng)你選擇了編輯菜單中的 Preferences 項(xiàng)時(shí),你將會(huì)看到一個(gè)設(shè)置對(duì)話框(如圖1-3)。在該對(duì)話框中,有控制 CodeWarr

10、ior 編輯器、調(diào)試器和其它許多功能的界面和行為的選項(xiàng)。在這一節(jié)中,我們將學(xué)習(xí)這些設(shè)置的使用。圖1-3:設(shè)置對(duì)話框你可以在自己的CodeWarrior中試試上述這些設(shè)置項(xiàng)。你可以先點(diǎn)擊問(wèn)號(hào)標(biāo)志,然后點(diǎn)擊你感興趣的項(xiàng)目,就可以得到一個(gè)有關(guān)該項(xiàng)目的用途的簡(jiǎn)短介紹,也可以從幫助菜單中得到更詳細(xì)的信息。通用設(shè)置*編譯設(shè)置(Build Settings):選擇是否在執(zhí)行編譯之前保存已打開(kāi)的源文件,以及有多少內(nèi)存被用于編譯工作; IDE之外(IDE Extras):幾個(gè)獨(dú)立的設(shè)置。比如指定CodeWarrior 是否使用一個(gè)第三方的文本編輯器一一因?yàn)榧傻木庉嬈鞑⒉皇呛芡昝?,這可以通過(guò)指定一個(gè)你慣用的編輯

11、器來(lái)替代它; 插件設(shè)置(Plug-In Settings):供插件開(kāi)發(fā)商調(diào)試他們的插件; 隱藏文件夾(Shielded Folders):在這里指定的文件夾在工程設(shè)計(jì)期間,或執(zhí)行查找和比較操作期間,將要被忽略掉。如果在你的工程級(jí)有一個(gè)巨大的“數(shù)據(jù)”文件目錄,而你又不想讓這些文件降低 CodeWarrior的操作速度時(shí),這個(gè)設(shè)置就很管用了; 資料樹(shù)(Source Trees):用于指定 CodeWarrior在編譯程序時(shí)用不著的目錄。編輯器設(shè)置 編輯器設(shè)置(Editor Settings):幾個(gè)用于定制編輯器顯示、管理文本和窗口的設(shè)置項(xiàng); 字體和制表符(Fonts and Tabs):設(shè)置編輯器

12、中的文本大小、字體、制表符和其它顯示設(shè)置; 文本顏色(Text Colors):用于指定特定語(yǔ)言元素(比如程序的注釋)在編輯窗口中的顯示的顏色 調(diào)試器設(shè)置 顯示設(shè)置(Display Settings):幾個(gè)用于定制調(diào)試器顯示的設(shè)置項(xiàng); 視窗化(Windowing):設(shè)定調(diào)試器如何管理它的窗口(比如隱藏所有打開(kāi)的編輯器窗口); 全局設(shè)置(Global Settings):幾個(gè)用于定制調(diào)試器在全局層次如何工作的設(shè)置。比如當(dāng)一個(gè)包含了程序調(diào)試信息的文件被打開(kāi)時(shí),是否啟動(dòng)這個(gè)程序; 遠(yuǎn)程連接(Remote Connections):允許通過(guò) TCP/IP進(jìn)行遠(yuǎn)程調(diào)試。這樣,你就可以在地球的另一邊調(diào)試你

13、的軟件了; Java 設(shè)置/Java 調(diào)試(Java Settings/Java Debugging):允許你設(shè)置特定的Java 編程語(yǔ)言選項(xiàng)。本課程不涉及這部分內(nèi)容。RAD工具 Layout編輯器:幾個(gè)用于在CodeWarrior中定制快速應(yīng)用程序開(kāi)發(fā)工具的使用的設(shè)置。正如你所見(jiàn)到的,CodeWarrior有許多設(shè)置項(xiàng)和選項(xiàng)。設(shè)置完后點(diǎn)擊“Save”按鈕保存你所作的修改,點(diǎn)擊“ Close”按鈕將忽略你所作的所有修改。在進(jìn)入下一節(jié)課之前,多練習(xí)幾次。最后請(qǐng)確認(rèn)“默認(rèn)的文本文 件格式(Default Text File Format) ”(在編輯器設(shè)置面板中)保持為 DOS設(shè)置。(待續(xù))附原文

14、:Lesson 1: Getting to Know CodeWarriorWhat Will CodeWarrior Do for Me?It can be frustrating to use other people's applications when you know you can make something better.But it can also be frustrating when you have a zillion lines of code and can't find the one typo that's making the wh

15、ole application go kablooey - not to mention getting it all compiled and linked and so on.This is why you are here. And this is why CodeWarrior was created.For now, we'll focus on writing programs in CodeWarrior using the C or C+ programming languages. This course assumes that you're pretty

16、comfortableusing atleast one of these languages. CodeWarrior alsosupports Java development, but that will be covered in a separate class. This course concerns itself with Windows platform development. Once you get really good at programming with CodeWarrior, you can explore the other platforms for w

17、hich tools have been designed. Much of what will be discussed here can also be applied to developing Mac applications.CodeWarrior automatically checks your code for obvious errors, helps you scan it for less obvious ones (via an integrated debugger and editor), and then compiles and links the code s

18、o that your computer can understand and execute your program. Every application that you have used has been through the coding, compiling, editing, linking, and debugging process, using tools like CodeWarrior.Now you cando it too! But we still have to teach you how.Using CodeWarrior, you can write j

19、ust about any type of program you can imagine. If you are a beginner, you may choose to write an application (also known as an executable) as your first program. You might choose to create something as basic as WordPad, Microsoft's text editor, for example.Applications are probably the simplest

20、type of program to write, though large commercial ones likeAdobe Photoshop, Microsoft Word and even CodeWarrior itself are quite complex. Other program types include control panels, dynamic linked libraries (DLLs), and plug-ins. Let's talk about these types for a minute.Under Windows, controlpan

21、els are those (usuallysmall) programs that are stored in your Control Panelsdirectory and visiblein the Control Panel section on the Start menu. The controlpanel itself is simplyan interface to a system-wide feature, like setting the sound volume or the mouse's motion speed, for example.DLLs sup

22、ply useful functions that are sharedby the operating system and applications. They typicallydon't have a user interfacePlug-insare similar to DLLs in that they provide small pieces of code that are used by other software.However, a single program typicallyuses this code. For example, Photoshop p

23、lug-ins allow programmersto easily extend the capabilities of the Photoshop application without having access to its source code. Likewise, many Web browsers use plug-ins that add extra features to the application or allow you to manipulate new content types on the Web. Many programs, including Code

24、Warrior,make use of this plug-in architecture.There are plenty of other types of programs you can write once you master CodeWarrior and the programming interfaces for your operating system. In fact, once you complete this course, you can take other courses in which you will learn more in-depth metho

25、ds of programming your computer. You've chosen an excellent place to begin your journey, however. So sit back, relax, and absorb the lessons in this course, and you'll be well on your way to becoming a CodeWarrior!An Introduction to the CodeWarrior ApplicationCodeWarrior is a complex applica

26、tion. If you really want to benefit from all of its features, you should take this time to get to know its various components and the capabilities that will be available to you. This first lesson will give you a basic overview of how the CodeWarrior IDE is set up. (That acronym gets thrown around a

27、lot, and it's short for Integrated Development Environment. ) We'll take a look at menus, windows, and other aspects of the program. Follow along with the CodeWarrior IDE while you read through these lessons. Start by launching the IDE application. If you followed the defaults for the CodeWa

28、rrior software installation, there will be an icon that represents a shortcut to the program. Double-click on it to start the IDE. If the shortcut icon is absent (these things happen), you can typically find the program at C:Program FilesMetrowerksCodeWarriorBinIDE.exe.ToolbarWhen you launch the Cod

29、eWarrior IDE, you'll notice a toolbar attached to the menu at the top of your screen. This toolbar (Figure 1-1) contains buttons that are shortcuts to frequently used menu items. You'll learn how to customize this toolbar - and even the entire IDE - in a later lesson. For now, notice that th

30、is toolbar can be used to quickly access features within the IDE.Figure 1-1: The CodeWarrior IDE toolbar.File MenuThe menus in the CodeWarrior IDE are set up in a relatively standard manner. The File menu contains choices that manage the care and feeding of files. It has standard items that let you

31、create, open, save, and print files.Edit MenuThe Edit menu will also seem familiar if you use other Windows applications.You'll find commandsthatcut, copy, and paste text, as well as a few other options to help programmers more easily manage source code layout. There is also a Preferences item i

32、n the Edit menu that we'll discuss later in this lesson.View MenuThe View menu (Figure 1-2) gives you options to manage which toolbars and other windows are displayed in the CodeWarrior environment. Some of these windows include various specialty windows, such as the Watchpoints window, Expressi

33、ons window, Processes window, and Global Variables window.Figure 1-2: The Toolbar submenu of the View Menu.Search MenuThe Search menu's commandsallow you to locate source code within a single file, or within the directories of your hard disk. You can also easily replace large blocks of text or s

34、earch your source code for references to other source code. These tools can be very handy, even for small projects.Project MenuTools in the Project menu allow you to manage CodeWarrior projects. A project includes all of the files that make up a program you are writing, including its headers, source

35、 code, and libraries. The Project window serves as a container for these files. We'll discuss this in more depth in Lesson 2.Debug MenuWhen your source code doesn't do exactly what you want it to (or your computer crashes when you run your program), you'll develop a close relationship wi

36、th the items on the Debug menu. We'll discuss debugging in Lesson 5.Window MenuThe Window menu gives you the basic options to manage cascading and tiling windows in the CodeWarrior environment.Help MenuLastly, use the Help menu to get online help with just about any item in CodeWarrior. Pretty c

37、ool setup, huh?Getting to Know IDE PreferencesThe CodeWarrior IDE has numerous preferences that you can use to customize your work environment. You may only want to change the text color, or you might want to get more personal, changing lots of settings. When you select Preferences from the Edit men

38、u, you are presented with the IDE Preferences dialog box (Figure 1-3). There, you'll find options that control the appearance and behavior of the CodeWarrior editor, debugger, and lots more. In this section, we'll take a look at these preferences.標(biāo)準(zhǔn)文案Figure 1-3: The Preferences dialog box.As

39、 each item is described below, follow along in your own copy of CodeWarrior, and check out the various options available. You can get additional help by clicking on the question mark, then the item you're interested in. You'll see a terse description of the selected item's purpose. More

40、detailed information is also available from the Help menu.The General Preferences Build Settings:Choose whether to save open-source code files before performing a build andhow much memory to use while building. IDE Extras:Various settings that don't belong anywhere else. Here's where you can

41、 haveCodeWarrior interoperate with a third-party text editor. The integration of editors with the IDE is often less than perfect, but this limitation may be offset by the ability to use an editor that you know and like. Plug-In Settings:Used by plug-in developers to assist in the debugging of plug-i

42、ns. Shielded Folders:Directories listed here are skipped (ignored) during project and/or findand compare operations. This can be useful if you have a large directory of "data" files inside your project hierarchy yet you do not want those files to slow down certain operations of CodeWarrior

43、. Source Trees:This lets you specify directories other than the standard ones CodeWarriorsearches when it builds a program.Editor Preferences Editor Settings:Various settings to customize the way the Editor displays and manages textand windows.f Fonts and Tabs:Text size, font, tab, and other display

44、 settings for the Editor windows. Text Colors: Like the browser display, you choose the color in which certain language elements (such as comments) appear in the Editor window.Debugger Preferences Display Settings:Various settings to customize the display of the debugger.w Windowing: How the debugge

45、r manages its windows (e.g., hiding any open editor windows). Global Settings:Various settings that customize how the debugger works on a global level,such as whether to launch a program when you open a file that contains the program's debugging information. Remote Connections: Allows debugging

46、over TCP/IP. You can debug software on a computer on the other side of the Earth! Java Settings/Java Debugging:Allows you to set specific java programming language options,not covered in this course.RAD Tools Layout Editor:Various settings to customize the use of rapid application development toolsw

47、ithin CodeWarrior.As you can see, there are numerous settings and options that can be set. Clicking the Save button will save any changes you've made. Clicking the Close box for the Preferences window will cause CodeWarrior to ignore any changes you've made. Go ahead and play with it a littl

48、e before you proceed to the next lesson. Make sure the Default Text File Format (in the Editor Settings panel) remains set for DOS.第二課顯示和定制工程和目標(biāo)文件(1)Translated from CodeWarriorU.COM本課將講述 CodeWarrior操作文件的方式以及介紹它的工程(Project) 窗口什么是工程文件為了使用 CodeWarrior來(lái)創(chuàng)建一個(gè)應(yīng)用程序,你必須創(chuàng)建許多文件來(lái)構(gòu)成一個(gè)工程(Project)該工程的設(shè)置和所有這些文件的指針都

49、被存放在一個(gè)工程文件中。這些設(shè)置包括編譯和鏈接設(shè)置、源文件、庫(kù)文件以及它們之間用于產(chǎn)生最終程序的相互關(guān)系。你可以將這個(gè)工程文件看作該工程的大腦:它保存了所有文件相互依存的關(guān)系并知道如何將它們組合成為一個(gè)可用的應(yīng)用程序。工程窗口依次顯示了這些關(guān)于你的程序和該程序所包含的文件的信息,并允許你只需輕松點(diǎn)擊就可以修改這個(gè)工程。圖2-1顯示了工程窗口的外觀。圖2-1:顯示工程信息的工程窗口(圖示為空的情況)大多數(shù)組成你的程序的文件都是原始的文本文件。這些文件包含了你在CodeWarrior的編輯器中鍵入的源代碼。在某些情況下,你還將使用一些預(yù)編11的源碼和頭文件。在進(jìn)行數(shù)學(xué)運(yùn)算和I/O操作時(shí),你還要使用

50、到一些庫(kù)文件,比如 Metrowerks標(biāo)準(zhǔn)庫(kù)(Metrowerks Standard Library , MSL)通常,你都是使用C 或 C+來(lái)編寫(xiě)源代碼,但通過(guò)給 CodewWarrior的集成開(kāi)發(fā)環(huán)境加裝相應(yīng)的插件(plug-in),你也可以在 CodeWarrior中使用其它語(yǔ)言來(lái)進(jìn)行編程。別忘了,CodeWarrior 可是一個(gè)可擴(kuò)展的集成開(kāi)發(fā)環(huán)境。通過(guò)給它安裝一些插件,你就可以擴(kuò)展它的功能。比如說(shuō),加入有人開(kāi)發(fā)了一種新的叫做 Z+的編程語(yǔ)言,你就可以為CodeWarrior創(chuàng)建一個(gè)相應(yīng)的插件使之能夠支持Z+語(yǔ)言,而且你還可以拿這個(gè)插件賣(mài)好多錢(qián),讓所有使用CodeWarrior編程的

51、人都使上Z+語(yǔ)言。那該多好?。?現(xiàn)在你知道了CodeWarrior是如何使用文件的了。下面我們來(lái)詳細(xì)地學(xué)習(xí)有關(guān)工程窗口的知識(shí)。工程窗口當(dāng)你啟動(dòng) CodeWarrior并打開(kāi)或創(chuàng)建一個(gè)工程時(shí),工程窗口就會(huì)顯示出來(lái)。該窗口用于管理整個(gè)工程的所有文件以及這個(gè)工程將要產(chǎn)生的目標(biāo)(targets) 文件。一個(gè)工程包含了足夠的信息來(lái)編譯一個(gè)或多個(gè)目標(biāo)文件。所謂的目標(biāo)(target)文件就是當(dāng)你編譯程序時(shí),由 CodeWariior創(chuàng)建出來(lái)的(通常是)一個(gè)應(yīng)用程序或庫(kù)文件。一些程序可以編譯產(chǎn)生多個(gè)目標(biāo)文件。比如,你可以編寫(xiě)一個(gè)程序來(lái)創(chuàng)建一個(gè)DLL和一個(gè)調(diào)用該 DLL的主應(yīng)用程序。在 CodeWarrior的

52、工程中,你可以定義一個(gè)目標(biāo)來(lái)廣生DLL,定義另一個(gè)目標(biāo)來(lái)產(chǎn)生應(yīng)用程序。通過(guò)這種方式,你的工程只需編譯一次就可產(chǎn)生所有需要的目標(biāo)文件或片斷。圖2-2 顯示了 “Hello World ”程序的工程窗口。 Hello Wdi Id.mcp-|a|x| 16 -C Consol e A pp D ebug三| 臉 * 啰尸 口Fifeg | Link Order Target - =:':= .:-,.":-:=">l*BI:»:s.l,1* 一*4 « 4 o u fa-f 3 o nu川o o O -n Q a 口 u U 口口n/rl/司目

53、 Source /圈 rmain.craMSLANSI Lbraries 胞 AnncaiBG.ib/;脂 ANSICXSGD.LIB心 MwcrrLIibMWEFJTLD.LIB 噂 El tB Win32 SDK Libiaries /!徑Gd32兄啜:Kiern&IJ2.lib& 胎 Ueer32.litj9 Ife圖 2-2: Hello World程序的工程窗口(其中顯示了所有包含于該程序中或用于編譯該程序的文件)你可以看到,在這個(gè)工程窗口中確實(shí)包含了一些項(xiàng)目。在窗口的頂端有三個(gè)標(biāo)簽(tab)頁(yè):文件標(biāo)簽(如圖2-2顯示)、鏈接順序標(biāo)簽頁(yè)和目標(biāo)文件標(biāo)簽頁(yè)(后兩個(gè)標(biāo)簽頁(yè)

54、將在后續(xù)課程中講述)。在這幾個(gè)標(biāo)簽頁(yè)的上方,有一個(gè)用于選擇要編譯的目標(biāo)文件的下拉菜單。在本例中,我們選擇的是Hello World工程的調(diào)試版本。在下拉菜單的右邊有幾個(gè)圖標(biāo),它們的存在允許你不必使用菜單命令就可以方便地編譯、鏈接和運(yùn) 行這個(gè)工程。注意:在某些版本的CodeWarrior 中,鏈接標(biāo)簽被稱(chēng)為段(segments)標(biāo)簽。有些人可能在某些X86的處理器上編程時(shí)使用的是分段(segmented)代碼。但使用 Windows版的 CodeWarrior工具時(shí)就不是這樣,這是產(chǎn)生的 X86代碼使用的是"扁平的"(flat),或者叫做非分段的(unsegmented) 內(nèi)

55、存空間。顧名思義,文件標(biāo)簽頁(yè)列出了在工程中所有可能用到的文件。你可以通過(guò)創(chuàng)建一些組 (用文件夾圖標(biāo)表示)來(lái)分門(mén)別類(lèi)地管理這些文件,并可以幫助你方便地了解哪些文件將被使用。在本例中,我們將C程序(以.c為后綴名的文件)全都放到一個(gè)叫做Source的組中,同時(shí)將庫(kù)文件放到另一個(gè)組中,以便整潔明了地管理這些文件。在 Sources 組中有一個(gè)main.c 文件。因?yàn)槲覀冞€沒(méi)有編譯這個(gè)工程,所以在每個(gè)文件對(duì)應(yīng)的 Code 和 Data 欄中顯示數(shù)字的都是零。一旦我們編譯了這個(gè)工程,這些數(shù)字就將顯示出來(lái),表示源 碼轉(zhuǎn)換為機(jī)器代碼后實(shí)際的代碼量和數(shù)據(jù)量??墒牵瑤?kù)文件ANSICX86.L舊 和 MWCRTL

56、.LIB后面顯示的是 n/a o這表示索雖然這些文件被顯示在這里,但是它們并不是Hello World目標(biāo)文件的一部分。這兩個(gè)文件是用于不可調(diào)試(non-debugging)開(kāi)發(fā)的,而本例不是這種情況。如果我們從菜單中修改本例的目標(biāo)文件為 Release(發(fā)布) 版本時(shí),這兩個(gè)文件就用得上了。這時(shí)這些文件后面的Code和 Data 欄目就會(huì)顯示相應(yīng)的數(shù)值。注意:在 Data 和 Code欄右端的Target 欄目中的小子彈頭也是用來(lái)表示該文件是否被當(dāng)前編譯生成的目標(biāo)文件使用到。再往右邊去,是 Debug欄(用一個(gè)綠色的小蟲(chóng)子表示),它是用于告訴你對(duì)應(yīng)的文件在編譯時(shí)是否要產(chǎn)生調(diào)試信息。我們將在第

57、五課中詳細(xì)論述這部分內(nèi)容。最后,我們來(lái)看看在每一行最右端的彈出菜單, 它是用于打開(kāi)文件、更新源碼、打開(kāi)包含的頭文件等等操作的快捷方式,具體是什么才作,要看它所代表的 項(xiàng)目的類(lèi)型而定?,F(xiàn)在讓我們來(lái)編譯這個(gè)Hello World工程并看看編譯后的工程窗口的情況。我們從 Project 菜單中選擇 Make命令來(lái)編譯該工程。這將更新所有需要編譯的文件并產(chǎn)生相應(yīng)的輸出文件一一在本例中是 Hello World這個(gè)應(yīng)用程序。 hello World iricp_gxCorisola App Debugj國(guó) $ K gFile寓 | Link Ordsr | Targets |Code6 6 K 306691 .1 1 Ru 2 -d q.3 3 5 n 2rl35E222 113d 1 K 3B 8900002 "03屁四山351923B-Q Sourcemain,c|日隼MSLAHSI Lbraries 胎 Msic毋Elib 瘴 ANSIDOGD.LIBI 晾 MwcrtLIibMWtRTLD.LIBWin32 SDK Libia限B Gd跑砧!. B Qr旭Q2Jb UserSZlib tiles102K 15Gk圖2-3:編譯工程后的工程窗口的顯示情況從圖2-3中

溫馨提示

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

最新文檔

評(píng)論

0/150

提交評(píng)論