DOC PREVIEW
Stanford CS 106B - Using Xcode for Macintosh

This preview shows page 1-2 out of 6 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS106B Handout #5MWinter 07-08 January 14, 2008Using Xcode for MacintoshIn CS106B, you have the option of writing your programs on the Mac or PC. For theMacintosh environment, you will write your programs using a C++ compiler by Applecalled Xcode. Our CS106 libraries were developed and tested on Xcode version 2.5which is available for free download from Apple’s developer site. Xcode 2.5 requiresMac OS X 1.4 (Tiger) or newer1. The libraries also work on Xcode 3.0 for Max OS X 1.5(Leopard). You can also use Xcode on the Mac OS computers in the public clusters oncampus. Please see the next section for instructions on how to do this.Using Xcode at a clusterXcode is available for use in the Lair (the Tresidder Macintosh cluster), on the Macs inMeyer library, and in the residential computer clusters. The 106 libraries will already beloaded on them, so you should be able to just open Xcode and proceed from “Creatingthe add2 project” section.Downloading your own copy of Xcode from the WebFirst, note that most versions of Mac OS X come with Xcode preinstalled. However, youshould check the version of Xcode you have. The easiest way to do this is to first openthe application. Then, from the Xcode menu, select “About Xcode”. The window thatopens should say what version you have. If it is version 2.5 or later, you have the correctversion. If not, use the following directions to download the most recent version.Use your web browser to connect to http://developer.apple.com/tools/Xcode/.Click on the Tools Download link.Then, if you have Mac OS X 10.4 (Tiger), click on the “Xcode 2.5 (DMG)” link. If youhave Max OS X 10.5 (Leopard), click on the “Xcode 3.0 (DMG)” link. At this point, ifyou do not have one, you will need to create an Apple account. However, creating anaccount is free, so go ahead and make one. Click on the Xcode 2.5 / Xcode 3.0 (DiskImage). This will begin the download. 1 If you have an earlier version of Mac OS and would like to use Xcode, contact us and we can give youspecial instructions- 2 -Once the download is finished, there should be a drive called “Xcode Tools” loaded.If not, double click on the downloaded file, “Xcode_2.5.1_8m1910_6936315.dmg” (itmay not be called exactly this; don’t worry if it isn’t). Inside the “Xcode Tools” drive,double click on “XcodeTools.mpkg”. This will open an installer for Xcode. Follow theinstructions in the installer, and when you are finished Xcode will be installed.Downloading and Installing the CS106 LibrariesHere you will download the special libraries, such as genlib, that we use in this course.To start, use a web browser to access the followinghttp://www.stanford.edu/class/cs106b/materials/libraries/CS106Libs_for_Xcode.zip. This will download the installer. If it does not start automatically, doubleclick on the download to start. Follow the instructions in the installer to install the CS106Libraries.Creating the add2 projectEvery program written using Xcode has a project that indicates what different programfiles need to be compiled together in order for the complete program to work. Note thatcurrently projects with spaces in their names will not create properly for StanfordProjects in Xcode. Instead of naming a project something like “My Project”, you shoulduse “MyProject” or “My_Project” or something else similar. We are going to create aproject that uses a simple pre-written program, named add2.cpp. You can download thecode for add2.cpp by using a web browser to go to the linkhttp://www.stanford.edu/class/cs106b/materials/examples/add2.cpp, and thenselect the "Save As" option from the File menu to saving the file to your own computer.Once you have the .cpp file, you will need to create an Xcode project and add the .cppfile we provide. You will go through the basic process described below for eachprogramming assignment that you do in this course, using your own code files.Start the Xcode application. It's a good idea to create an alias for this program and placeit on your desktop or in another convenient place. You can also put it in your programdock. Select New Project... from the File menu. The following dialog will appear:http://see.stanford.edu/materials/icspacs106b/CS106Libs_for_Xcode.zipzippziphttp://see.stanford.edu/materials/icspcs106b/add2.cpp- 3 -Now you need to tell Xcode what type of project you are creating, what to call it, andwhere to put it. First, highlight "Stanford CS106 C++" in the list on the left, then click“Next”. Type “Example_Project” as the name of the project.Now you have to show where the project should be located. Xcode has a default location,which you can use if you’d like. Otherwise, click “Choose...” and use the resulting dialogto select where you’d like the project to be. Note that the end of the location will be thesame name as your project (e.g., “~/Example_Project/”). This is a folder Xcode willautomatically create to store the project files.Click OK. The project is now created.How to Use the Xcode Project WindowThe Xcode project window has a number of folders and buttons. You will only need touse a few of them; this section will walk you through them.- 4 -1. This is your project folder. When you want to create a new file or add an existing file,you right click on this folder and select the appropriate option.2. Selecting this folder will show you the current errors or warnings in the current project.Note that they will not appear until you build the project (build means to create a machinereadable version of your code).3. This button will build the project.4. This button will build and, if there are no errors, run the project.Adding add2.cpp to the Example ProjectTo start, move add2.cpp into the project folder that Xcode created for“Example_Project”. Then, in Xcode, right click on the project folder (1, above). Mouseover “Add” and then select “Existing Files”. The starting folder should be your projectfolder, so click on “add2.cpp”. If not, navigate to the project folder, and then click onadd2.cpp. Click “Add” and then “Add” again on the resulting dialog window. add2.cppis now loaded into your project.Building and Running add2.cppAt this point, you can run the add2 program. You can do this in one of a couple ways.The easiest way is to click on the “Build and Go” button (4, above). If you openedadd2.cpp, there is a corresponding button in that window that you can also click on.Two new windows


View Full Document

Stanford CS 106B - Using Xcode for Macintosh

Download Using Xcode for Macintosh
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Using Xcode for Macintosh and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Using Xcode for Macintosh 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?