The Mac Observer

OS X Lion for UNIX Geeks: Installing the C Compilers

TMO Talk (37)

Out of the box, OS X doesn’t include the standard C compilers (C, C++, Obj-C). While they are unnecessary for the average customer, many technical users (or people learning C for the first time) like to have access to a C compiler on the command line — without delving into Apple’s comprehensive development system and the Xcode IDE. Here’s how to do it — for free.

The first thing to know is good news. You don’t have to pay US$99 and become a member of Apple’s Developer program to follow these instructions. You can download Apple’s Xcode 4.1 for free, and its installer will give you gcc, g++, and llvm-gcc nicely installed and ready for the command line. The bad news is that you’ll have to be using Lion. And, you’ll need to have an Apple ID, even though the download is free.

What starts this odyssey for most technical users is that they’re perusing a new Mac, open a terminal, and type, out of curiosity:

gcc -v

and find to their dismay that that there’s no C compiler to be found. WTF?

gcc1

The Ugly “Before”

Unlike most other UNIX vendors, Apple feels that this is an unnecessary addition and that technical users, if they need it, can go install it. However, those who are new to the Mac are often not quite sure about the best way to do that. Here’s the easy way.

________

1. First, go to the Apple menu in Lion and select “App Store…” Do a search for “Xcode.” You should see something similar to this. (Note, in my case, Xcode is marked as already installed.)

MAS

Mac Apple Store (MAS) Xcode on the left.

2. After you download Xcode, there will be an installer in /Applications. It looks like this in icon view.

Xcode installer

 

Xcode Installer icon

3. Double click this application, if it didn’t already launch after the download, and a complete development system will be installed on your Mac and placed in the root of the file system — in a directory called “Developer.” You can explore the contents and the Integrated Development Environment (IDE) at your leisure. So just go ahead and quit Xcode (CMD-Q) after the installer is done.

Welcome to Xcode

You won’t be needing this right away, so quit the app.

4. Now open the terminal and type “gcc -v” again. Bliss!


gcc-after

The Beautiful “After”

You’ll notice that gcc 4.2.1 is installed. Also, g++ is installed. For those who prefer, the more modern Low Level Virtual Machine (LLVM) C compiler that Apple is now using is also installed. These are all in the expected place: /usr/bin. Note that the Xcode installer also drops in the man pages for these compilers.

llvm pointers

llvm pointers in /usr/bin

Additional Notes

That’s all you need to do. If at some future point, you want to explore GUI app development on the Mac, you can learn Xcode, found in /Developer/Applications as well as the primary development language for OS X and iOS apps called Objective-C. (The version of gcc installed will compile Objective-C code.)

To learn more about how Apple has implemented llvm-gcc, the default compiler in Xcode, here’s a really good, quick and handy reference article to digest before you dig into Apple’s extensive developer documentation.

Apple is no longer maintaining gcc, so you might as well move to llvm-gcc on the command line.

Finally, the sake of completeness, I should add that Dr. Gaurav Khanna, an astrophysicist in the Physics Department at the University of Massachusetts at Dartmouth, maintains a computational tools page that goes well beyond the simple C compilers mentioned above. He generally keeps these tools updated for the latest version of OS X.

________

UPDATE: April 4, 2012. Things have changed slightly since this article was written. See this update: “Install the Command Line C Compilers in OS X Lion.”

Post A Comment or Log-in. Need an account? Register here.
 

Recent Headlines - Updated May 27th

Sat, 10:00 AM
MacOS KenDensed - MacOS KenDensed: Apple’s Patent Lawsuit & Antitrust Shuffle
Fri, 5:58 PM
News - Sotheby’s to Auction Steve Jobs Atari Memo (Photo Gallery)
5:42 PM
Free on iTunes - 3 Free iOS Apps for News Hounds
3:00 PM
Rumor - Nest Thermostat Reportedly Coming to Apple Retail Stores
2:40 PM
Particle Debris - The TV Industry’s Dreadful Little Secret
2:33 PM
News - Mobile Devices Account for 20% of Web Traffic in US, Canada
12:49 PM
News - Apple Now Offering “Free App of the Week” for iOS
12:21 PM
News - Tim Cook Declines $75 Million Dividend Payout
11:25 AM
News - Absinthe 2.0 Provides Untethered Jailbreak for iOS 5.1.1
11:09 AM
Quick Look Review - F18 Carrier Landing (iOS) is a Boatload of Fun
10:51 AM
TMO Appearances - Jeff Gamet talks Cool Apps & Accessories on Not Another Mac Podcast
10:12 AM
Hot Forum Topic - Forum Poll: Which is Your Favorite Photo Sharing Service?
 

The Mac Observer Reader Specials

  • Macsales.com SuperSpeed SSDs from $58. Transform your Mac with an SSD Solution of up to 960GB! You won't believe it's the same machine! Once you experience an OWC SSD, no going back! - Macsales.com
  • Mac RAM Upgrades: MacBook Pro 16GB kits $475, 8GB Kits for $119.99! iMac 16GB RAM Kits (4x 4GB) for $229.99! Mac Pro Memory 32GB Kit for $399.99, 64GB Kit for $889.99! Mac Hard Drives 2TB Seagate SATA II for $249.99! Click Here!
  • Macpokeronline.com If you're using a Mac, then you've gotta check out PokerOnAMac.com. Online casinos and poker rooms are literally giving away cash and the casino sites at Poker on a Mac do the unthinkable, they actually reward! Join today, the download is free!
  •  Looking to find online casinos for mac? We can help you find the best real money casino sites where you can play your favorite casino games including blackjack and slots.

Apple Stock Quote (AAPL)

Loading...

Hot Topics

TMO Express

Join the TMO Express Daily Newsletter to get the latest Mac headlines in your e-mail every weekday. Find out more!

Top Deals From DealBrothers.com

Recent Features

Support The Mac Observer

We noticed you may be running AdBlock on your computer. It takes real money to run this site and to deliver the news, tips, and opinions you love to read.

If you wish to block the ads that pay for the creation of our content, we ask that you instead support TMO Directly, either with a $5 monthly recurring contribution, or a one-time donation of any amount of your choice. Thanks!

Subscribe with Paypal Donate with Paypal