TweetFollow Us on Twitter

A Taste of Project Builder

Volume Number: 19 (2003)
Issue Number: 1
Column Tag: Getting Started

A Taste of Project Builder

by Dave Mark

As promised in last month's column, this month we're going to take a walk through the Project Builder debugger. Before we do, I want to touch on an issue that has been raised by a number of readers, especially folks who work in both CodeWarrior and Project Builder.

Where the Heck is the Standard Library?

CodeWarrior and Project Builder each have their own distinctive look and feel, especially when it comes to the Project Window. One point of confusion concerns the location of the Standard Library. In CodeWarrior, the Standard Library is (typically) explicitly included in the project. Sometimes this is done by creating a project from a Metrowerks Standard Library (MSL) template. Other times, you add the MSL library to your project yourself, choosing from a selection of precompiled versions of the MSL, or perhaps custom compiling your own version.

Bottom line, when you look at your Project Window, you know you've got MSL in your project because it is listed in the window along with all your other source code, libraries, etc. Want to get rid of the MSL? Select it and hit the delete key.

Project Builder follows a different tack. In the Project Builder Project Window, there is no explicit reference to the Standard Library. The question people are asking is, "Where the heck is it?"

Dave Payne, from Apple's Developer Tools team, kindly cleared away the mist:

    With gcc on Mac OS X, the "standard C library" (sometimes known as libc on Unix systems) is part of System.framework, which is implicitly brought in by gcc when linking. System.framework is a dynamic shared library, shared by all apps on the system, which reduces overall system memory use.

    If the application uses C++, gcc also automatically brings in /usr/lib/libstdc++.a, which is a static library. We currently recommend that developers avoid building frameworks (shared libraries) with C++ APIs, to avoid binary compatibility problems, because gcc's C++ ABI has been in some flux.

    One other thing to note: for C & Objective-C APIs, we encourage the creation and use of frameworks. If someone does want to build a static library and link it into their app, they currently need to follow the standard Unix naming convention of lib<foo>.a. See this Q&A for more info: http://developer.apple.com/qa/qa2001/qa1101.html

    Some of our conventions derive from wanting to help enable easy porting of Unix programs to Mac OS X; we need to balance the use of Unix conventions and Mac conventions, and try to make things seamless for everyone.

Interesting stuff. If you launch Project Builder, then click on the Targets tab, you'll see a list of various settings, as well as a sequence of Build Phases steps. Figure 1 shows the Frameworks & Libraries Build Phase. Dave's point above was that the Standard Library wasn't listed in this pane because it is built into System.framework and implicitly brought into the link process, not as an additional library added to the project.


Figure 1. Project Builder's Targets pane, showing no additional Frameworks & Libraries.

When I sent Figure 1 to Dave Payne, I asked him if Project Builder made use of makefiles. For you non-Unix folks, a makefile is a text file containing a script for building an application. Typically, a makefile will contain a series of build instructions, depending on the target being built. Project Builder's Target pane is, in effect, a graphical makefile. I was asking Dave if there was an actual makefile underneath it all:

    Any other frameworks and libraries besides System.framework and libstdc++ will appear in the area you show in the screen shot. The "Sources" Build Phase shows the compilation and link order of project source files.

    No, there is no makefile under the interface that folks can look at. The internals of the build system are an implementation detail which we may change in the future. A developer can look at the detailed build log if they want to see the actual commands that get run during a build. To see the detailed build log, drag up the split bar at the bottom of the build pane so that the summary is at the top and the detailed log is visible below.

To get a sense of this, check out Figure 2. It shows the Build window from the Hello, World project with the split bars dragged wide open to reveal the Build specifics. Personally, I'd like to see this process opened up a bit more so I might tweak my compile/link instructions directly. Perhaps in a future version of Project Builder.


Figure 2. The Build window from our Hello, World project.

Play with Your Debugger

As promised, I'd like to spend a bit of time going through Project Builder's debugger interface. Launch Project Builder, then select New Project... from the File menu. Our last Project Builder effort was a project of type "Standard Tool". This was equivalent to a Standard Library based C console app. This month, we'll create a project of type "Foundation Tool". Name the project Hellobjc and store it in the same directory as your other projects.

The Foundation Tool project is based on the Foundation object framework and links in the Objective-C library. Over time, we'll tackle the syntax of the Objective-C language and become familiar with the classes that make up the Foundation framework. For now, let's play with this project and see if we can't learn a bit about how the debugger works.

In the project window, click on the Targets tab (the tabs are arranged vertically - sideways) and the Targets tab is fourth from the top. In the list that appears, click on the Hellobc target (you may need to click on the Targets disclosure triangle to reveal the Hellobc target). In the new pane that is revealed, under Settings, then under Simple View, click on the item GCC Compiler Settings (Remember last month's Terminal project? You compiled your source code with the command "gcc." GCC is the GNU C Compiler).

Make sure that the "Generate debugging symbols" check box is checked. This tells project builder to include debugging information when it compiles your code, allowing you to use the debugger to debug your program. Very important! Take a look at Figure 3 to get a sense of what this looked like on my machine.


Figure 3. Make sure the "Generate debugging symbols" checkbox is checked.

Before we try out the debugger, take the program for a spin. Click on the icon with the tool-tip "Build and run active executable" (check out Figure 4). The Build window will appear and the program should compile and, finally, the Run window will appear showing our classic "Hello, World!" output, much as it did in the C-based Hello, World project.


Figure 4. Click on the third icon to build and run your project.

Now close the Run and Build windows, leaving the Project window open. Click on the Files tab, then select the file main.m (you'll find it under Source). As a reminder, Objective-C source files end with the extension ".m". Here's the default source code from main.m:

#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    // insert code here...
    NSLog(@"Hello, World!");
    [pool release];
    return 0;
}

Let's replace the "insert code here..." comment with a simple for loop we can follow in the debugger. Here's the new version of main.m:

#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
   // Adding a for loop for debugging fun...
   int   count;
   for ( count=1; count<=3; count++ )
   {
    NSLog(@"Hello, World!");
   }
   [pool release];
   return 0;
}

Note that we replaced the NSLog() call in the original code with a loop that calls NSLog 3 times. Run your new code. You should see the familiar console window, but this time with 3 lines of "Hello, World!" NSLog() is a function you can use to get output to the console window and the square brackets are mechanisms you use to send messages to objects designed to receive those messages. In the code above, we send an "alloc" message to the NSAutoreleasePool object, then send the resulting object an "init" message. When we are done, we send the object a "release" message. Not to worry, we'll start digging into this syntax next month.

For now, let's take this new code for a spin in the debugger. Close your Run and Build windows (not necessary, just doing this to avoid confusion). In your Project window, note the blank column just to the left of your source code. This column holds your breakpoints and tell the debugger when to stop and wait for your input.

Click just to the left of the for loop to create a breakpoint there. Figure 5 shows the breakpoint icon that appears.


Figure 5. Click in the source code to create a Breakpoint.

Now lets run the debugger. Click on the hammer/spray can combo icon in the upper-left of the Project window. The debugger window will appear (Figure 6), the program will start running, and the debugger will stop at our breakpoint, immediately before executing the for loop. Notice the pink highlight bar that highlights the line of code that is about to get executed.


Figure 6. The debugger, stopped just before executing your for loop.

Now step through the execution of your program using the controls that appear in the upper right corner of the debugger window. The triangle restarts execution from the beginning of your program. The second icon, pauses execution, just as if the program had hit a breakpoint. The next icon resumes execution until the next breakpoint or until your program exits. The fourth icon is one you'll use a lot. Its tool-tip says "Step over method or function call." Basically, it tells your program to keep executing to the next line of code in the current source file. If the current line is a function call, it completely executes the function call, stopping before the next line of code after the function call.


Figure 7. Click "Step over method or function call" to go to the next line of code.

The next icon actually steps into the function, stopping at the first line of code within the function itself. The last icon finishes execution of the current function, stopping at the next line of code within the calling function. Add a function to the code and give these controls a try.

As you might expect, the fields that show the variable values update as you step through the program. Notice that the variable count starts with a value of 0 and then increments each time through the loop. You can add breakpoints during execution by clicking next to a line of code in the breakpoint column. Want to get rid of a breakpoint? Click and drag to the left or right. Move a breakpoint by dragging up or down.

To view your Standard Library output, click on one of the two tabs towards the upper right corner of the debugger window. The Console pane is a log of important debugger events interleaved with your standard i/o. The Standard I/O window is pure, listing only the i/o itself, each tagged with a time-stamp and a code you can use to link a statement to a specific execution of the program. Each time you restart your program, the code changes, and all i/o from that run will have the same code.

Want to change a variable? Piece of cake. You can double-click on a variable's value and, when the edit field appears, type in a new one. You can also double click on a variable name and a new window will appear, letting you track that variable separately. Cool!

Till Next Month...

Spend some time playing with the debugger. Create some code (go back to a Standard Library tool if you are uncomfortable mucking with Objective C), add some functions, play, play, play. The debugger is an incredibly important tool and you should experiment with it until you feel comfortable using it.

See you next time!


Dave Mark is very old. He's been hanging around with Apple since before there was electricity and has written a number of books on Macintosh development, including Learn C on the Macintosh, Learn C++ on the Macintosh, and The Macintosh Programming Primer series. Check out Dave's web site at http://www.spiderworks.com

 
AAPL
$97.03
Apple Inc.
-0.16
MSFT
$44.40
Microsoft Corpora
-0.47
GOOG
$593.35
Google Inc.
-2.63

MacTech Search:
Community Search:

Software Updates via MacUpdate

Audio Hijack Pro 2.11.0 - Record and enh...
Audio Hijack Pro drastically changes the way you use audio on your computer, giving you the freedom to listen to audio when you want and how you want. Record and enhance any audio with Audio Hijack... Read more
Intermission 1.1.1 - Pause and rewind li...
Intermission allows you to pause and rewind live audio from any application on your Mac. Intermission will buffer up to 3 hours of audio, allowing users to skip through any assortment of audio... Read more
Airfoil 4.8.7 - Send audio from any app...
Airfoil allows you to send any audio to AirPort Express units, Apple TVs, and even other Macs and PCs, all in sync! It's your audio - everywhere. With Airfoil you can take audio from any... Read more
Microsoft Remote Desktop 8.0.8 - Connect...
With Microsoft Remote Desktop, you can connect to a remote PC and your work resources from almost anywhere. Experience the power of Windows with RemoteFX in a Remote Desktop client designed to help... Read more
xACT 2.30 - Audio compression toolkit. (...
xACT stands for X Aaudio Compression Toolkit, an application that encodes and decodes FLAC, SHN, Monkey’s Audio, TTA, Wavpack, and Apple Lossless files. It also can encode these formats to MP3, AAC... Read more
Firefox 31.0 - Fast, safe Web browser. (...
Firefox for Mac offers a fast, safe Web browsing experience. Browse quickly, securely, and effortlessly. With its industry-leading features, Firefox is the choice of Web development professionals... Read more
Little Snitch 3.3.3 - Alerts you to outg...
Little Snitch gives you control over your private outgoing data. Track background activityAs soon as your computer connects to the Internet, applications often have permission to send any... Read more
Thunderbird 31.0 - Email client from Moz...
As of July 2012, Thunderbird has transitioned to a new governance model, with new features being developed by the broader free software and open source community, and security fixes and improvements... Read more
Together 3.2 - Store and organize all of...
Together helps you organize your Mac, giving you the ability to store, edit and preview your files in a single clean, uncluttered interface. Smart storage. With simple drag-and-drop functionality,... Read more
Cyberduck 4.5 - FTP and SFTP browser. (F...
Cyberduck is a robust FTP/FTP-TLS/SFTP browser for the Mac whose lack of visual clutter and cleverly intuitive features make it easy to use. Support for external editors and system technologies such... Read more

Latest Forum Discussions

See All

LEX Goes Free For One Day In Honor of Ne...
LEX Goes Free For One Day In Honor of New Update Posted by Jennifer Allen on July 24th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Thomas Was Alone Goes Universal, Slashes...
Thomas Was Alone Goes Universal, Slashes Price to $3.99 Posted by Ellis Spice on July 24th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Meerkatz Challenge Review
Meerkatz Challenge Review By Jennifer Allen on July 24th, 2014 Our Rating: :: FONDLY PUZZLINGUniversal App - Designed for iPhone and iPad Cute and challenging, Meerkatz Challenge is a fun puzzle game, particularly for fans of... | Read more »
Book Your Appointment with F.E.A.R. this...
Book Your Appointment with F.E.A.R. | Read more »
It Came From Canada: Epic Skater
For all the hate that it gets for being a pastime for slackers, skateboarding really does require a lot of skill. All those flips and spins take real athleticism, and there’s all the jargon to memorize. Fortunately for us less extreme individuals,... | Read more »
Cultures Review
Cultures Review By Jennifer Allen on July 24th, 2014 Our Rating: :: SLOW-PACED EMPIRE BUILDINGiPad Only App - Designed for the iPad Cute it might seem, but Cultures is a bit too slow paced when it comes to those pesky timers to... | Read more »
More Paintings Have Been Added to Paint...
More Paintings Have Been Added to Paint it Back! Posted by Jessica Fisher on July 24th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
The Order of Souls Review
The Order of Souls Review By Campbell Bird on July 24th, 2014 Our Rating: :: STORY GRINDUniversal App - Designed for iPhone and iPad The Order of Souls is a free-to-play, turn-based RPG with a genre-mixing art style, interesting... | Read more »
Revolution 60 Review
Revolution 60 Review By Jordan Minor on July 24th, 2014 Our Rating: :: LASS EFFECTUniversal App - Designed for iPhone and iPad Revolution 60 is a bold, cinematic action game with ambition to spare.   | Read more »
Matter (Photography)
Matter 1.0.1 Device: iOS Universal Category: Photography Price: $1.99, Version: 1.0.1 (iTunes) Description: Add stunning 3D effects to your photos with real-time shadows and reflections. Export your creations as photos or video loops... | Read more »

Price Scanner via MacPrices.net

Mac minis on sale for $100 off MSRP, starting...
Best Buy has Mac minis on sale for $100 off MSRP. Choose free shipping or free instant local store pickup. Prices are for online orders only, in-store prices may vary: 2.5GHz Mac mini: $499.99 2.3GHz... Read more
Global Tablet Market Grows 11% in Q2/14 Notwi...
Worldwide tablet sales grew 11.0 percent year over year in the second quarter of 2014, with shipments reaching 49.3 million units according to preliminary data from the International Data Corporation... Read more
New iPhone 6 Models to Have Staggered Release...
Digitimes’ Cage Chao and Steve Shen report that according to unnamed sources in Apple’s upstream iPhone supply chain, the new 5.5-inch iPhone will be released several months later than the new 4.7-... Read more
New iOS App Helps People Feel Good About thei...
Mobile shoppers looking for big savings at their favorite stores can turn to the Goodshop app, a new iOS app with the latest coupons and deals at more than 5,000 online stores. In addition to being a... Read more
Save on 5th generation refurbished iPod touch...
The Apple Store has Apple Certified Refurbished 5th generation iPod touches available starting at $149. Apple’s one-year warranty is included with each model, and shipping is free. Many, but not all... Read more
What Should Apple’s Next MacBook Priority Be;...
Stabley Times’ Phil Moore says that after expanding its iMac lineup with a new low end model, Apple’s next Mac hardware decision will be how it wants to approach expanding its MacBook lineup as well... Read more
ArtRage For iPhone Painting App Free During C...
ArtRage for iPhone is currently being offered for free (regularly $1.99) during Comic-Con San Diego #SDCC, July 24-27, in celebration of the upcoming ArtRage 4.5 and other 64-bit versions of the... Read more
With The Apple/IBM Alliance, Is The iPad Now...
Almost since the iPad was rolled out in 2010, and especially after Apple made a 128 GB storage configuration available in 2012, there’s been debate over whether the iPad is a serious tool for... Read more
MacBook Airs on sale starting at $799, free s...
B&H Photo has the new 2014 MacBook Airs on sale for up to $100 off MSRP for a limited time. Shipping is free, and B&H charges NY sales tax only. They also include free copies of Parallels... Read more
Apple 27″ Thunderbolt Display (refurbished) a...
The Apple Store has Apple Certified Refurbished 27″ Thunderbolt Displays available for $799 including free shipping. That’s $200 off the cost of new models. Read more

Jobs Board

*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Sr. Project Manager for *Apple* Campus 2 -...
…the design and construction of one building or building components of the New Apple Campus located in Cupertino, CA. They will provide project management oversight for Read more
WW Sales Program Manager, *Apple* Online St...
**Job Summary** Imagine what you could do here. At Apple , great ideas have a way of becoming great products, services, and customer experiences very quickly. Bring Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Project Manager / Business Analyst, WW *Appl...
…a senior project manager / business analyst to work within our Worldwide Apple Fulfillment Operations and the Business Process Re-engineering team. This role will work Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.