home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeMac OS X for Unix GeeksSearch this book

Chapter 4. Compiling Source Code

The Mac OS X Developer Tools are available from Apple and provide a development environment that will be familiar to any Unix developer whoworks with command-line compilers. For details about obtaining these tools, see the "Developer Tools" section in the Preface. The Developer Tools include all sorts of other goodies, including an advanced Integrated Development Environment (IDE), but coverage of those tools is beyond the scope and intent of this book. To learn more about the Developer Tools, you can see /Developer/Documentation/DeveloperTools/devtools.html. You can also learn how to use Project Builder and Interface Builder and how to program Cocoa applications with Objective-C in Learning Cocoa with Objective-C (O'Reilly) and Building Cocoa Applications: A Step-by-Step Guide (O'Reilly).

The C compiler that comes with the Developer Tools is based on the Free Software Foundation's GNU Compiler Collection, or GCC. Apple's modifications to GCC include the addition of Objective-C to the compiler suite, as well as various modifications to deal with the Darwin operating system. The development environment in Mac OS X includes:

AppleScript
This is an English-like language used to script applications and the operating system. AppleScript is installed as part of the Mac OS X operating system and does not require the Developer Tools package.

AppleScript Studio
This is a high-level development environment based on AppleScript that allows you to build GUI applications by hooking AppleScript into the Cocoa frameworks. AppleScript Studio is installed along with the Developer Tools package.

Compilers
These compilers are based on GCC and provide support for C, C++, Objective-C, Objective-C++, and assembly.

Compiler Tools
These include the Mac OS X Mach-O GNU-based assemblers, Mach-O static link editor, Mach-O dynamic link editor, and Mach-O object file tools, such as nm and otool.

Documentation
There is extensive documentation for the Apple Developer Tools (provided by Apple). Available in both HTML and PDF formats, the developer documentation can be found in /Developer/Documentation. The documents are also available online from the Apple Developer Connection (ADC) web site (http://connect.apple.com).

TIP: You can also access the documentation for GCC with your web browser by going to /Developer/Documentation/DeveloperTools/Compiler/CompilerTOC.html.

Debugger
The Apple debugger is based on GNU gdb.

Miscellaneous Tools
These include traditional development tools, such as GNU make and GNU libtool, graphical and command-line performance tools, Project Builder for WebObjects (Mac OS X Server), and an extensive set of Java development tools.

Project Builder
This is an integrated development environment for Mac OS X that supports Cocoa and Carbon programming with C, C++, Objective-C, and Java.

Interface Builder
This is a graphical user interface editor for Cocoa and Carbon applications.

We will not address the complete Mac OS X development suite in this chapter. Instead, we will focus on the command-line development tools and how they differ from the implementations on other Unix platforms.

Java programmers will find that the Mac OS X command-line Java tools (see Section 1.6.4) behave as they do under Unix and Linux.

Perl programmers coming from previous Macintosh systems will find that Mac OS X does not use MacPerl (http://www.macperl.com), but instead, uses the standard Unix build of the core Perl distribution (http://www.perl.org).

4.1. Compiler Differences

GCC is supported on a wide range of platforms and is familiar to most Unix developers. A natural consequence of this is that most Unix developers will find a familiar development environment in Mac OS X. There are, however, some important differences.

One difference that experienced GCC users may notice, particularly if they have dealt with a lot of mathematical and scientific programming, is that Mac OS X's Developer Tools do not include FORTRAN. However, the Fink distribution (http://fink.sourceforge.net) includes g77 , the GNU FORTRAN '77 compiler. Also, the Darwin archive includes the source code for g77, which you can use to compile FORTRAN code. For more information on the Darwin CVS archive, see Chapter 7.

TIP: Mac OS X's C compiler contains a number of Mac OS X-specific features that have not been folded into the main GCC distribution. (It is up to the Free Software Foundation (FSF) to accept and merge Apple's patches.) For information on how Apple's compiler differs from the GNU version, see the README.Apple file in the Darwin CVS archive's gcc3 subdirectory.

As of this writing, Apple's cc compiler is based on GCC 3.1. However, GCC 2.95 is also available as /usr/bin/gcc2. By default, invoking cc or gcc will invoke GCC 3.1. You can change this to GCC 2.95 by running the command gcc_select 2, and you can change it back with gcc_select 3. You can see the current settings by running gcc_select with no arguments:

% gcc_select 
Apple Computer, Inc. GCC version 1161, based on gcc version 3.1
20020420 (prerelease)
TIP: You can find the Mac OS X Compiler Release Notes on your system at /Developer/Documentation/ReleaseNotes/Compiler.html. You should consult these release notes for details on the most current known problems, issues, and features.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.