Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

GCC for OS X

Hi! im interested in learning C.. but i dont know how to run GCC on OS X.. I think i installed it but how do I run it? or if i do it through Xcode.. how do I make a C file?

MacBook, Mac OS X (10.4.10)

Posted on Apr 16, 2008 11:57 AM

Reply
18 replies

Apr 16, 2008 12:45 PM in response to Fios89

It depends on what you're trying to do.

If you're trying to create a mac application with buttons and slides and whistles, you run xcode, create a project and work from there.

If you're just trying to write a program that will spit out the first 100 primes or something, (hello world, 100 bottles of beer on the wall, whatever) then I'd recommend picking an editor (vi, emacs, pico, textedit, whatever) coding up a file that ends in .c and saving it. (say foo.c)

Then you go to the Terminal (under utilities) at the terminal you cd to where your file is (probably: cd Documents) and type gcc -o foo foo.c

that will create an executable called foo which you can run by typing foo at the next prompt.

I'm not sure what your or C knowledge is, so if that was at the wrong level, I'm sorry

Apr 16, 2008 12:46 PM in response to Fios89

The best way to install gcc is to install the developer tools from Apple. Even if you don't want to use Xcode or the other tools it will install gcc and make all the necessary arrangements for it to work.

If you want to use gcc to compile your C from the command line then use Terminal to gain access to the command line and use just about any C tutorial that is designed for Unix. A capable text editor like TextWrangler will be a big help eventually as well.

Here's an OS X specific tutorial: http://cocoadevcentral.com/articles/000081.php

This site has a lot of good tutorials for the beginner on it.

Hope that helps,

=Tod

Apr 16, 2008 12:53 PM in response to Brian Postow

Well im not sure what I want to do.. I got this book called The C Programming Language Second edition cuz someone i know told me C is an excellent start to programming. I have a little experience in doing Java.. and I like HATE IT... So Id like to learn like C in general.. eventually id like to make apps for mac but i figure Id use cocoa with objective C for that.. for now I just want to learn C and i wasnt sure how to go about it.. but my friend told me GCC is good

Apr 16, 2008 1:38 PM in response to Fios89

Fios89 wrote:
I have a little experience in doing Java.. and I like HATE IT...


What don't you like about Java. I'm not trying to start a Java-bashing thread, I just want to find out what kinds of programming you would like to do. There are lots of languages, architectures, and paradigms to choose from.

So Id like to learn like C in general..


While C and Java are very different beasts, there are some other critters that you might like better. I wrote C and C++ for 15 years, but I wouldn't touch them today. I use Perl and Objective-C/Cocoa now and I love it.

What do you really want to get out of it? What kinds of software do you want to write?

Apr 16, 2008 1:43 PM in response to etresoft

I dont mean to bash Java either.. but with what I have experienced with it.. I really dont like it and I find it confusing.. In terms of what I want to do with C? I really dont know.. Im in college right now a freshman.. and I want to become a software developer eventually.. maybe even for apple! So I guess I want to develop software apps? I dont wanna do things like hardware drivers or bios or stuff like that...

Apr 16, 2008 2:37 PM in response to Fios89

C is a procedural language, Java is an object oriented language. They require two different mind sets. For todays world and especially for Apple, I would recommend the object oriented mind set. Especially since you stated that you were interested in application level and not system level programming.

Apr 16, 2008 2:56 PM in response to xnav

That is true.. but from what I was told C is a great start and that I can use it to migrate into Objective C, and Cocoa with Objective C which are object oriented... and plus it cant hurt me to know a procedural language eh? I originally did Cocoa with Objective C so I got stuck.. so I figured id go down to the bare bones.. C since ObJ C is an extension of C.

Apr 16, 2008 3:01 PM in response to Fios89

Pedagogically speaking, C is a horrible language. It's like learning how to cut your food with the sharpest knife in the drawer. You give a sharp knife to a 4 year old, and you're going to get blood.

C is the same. it's very easy to do something dangerous, and stupid. Java is to a large extent a duller blade.

Java lets you shoot yourself in the foot.

C hands you the gun and helps you aim.

C++ hands you a bazooka aims it, and says "Please PLEASE blow off your own leg."

Apr 16, 2008 3:14 PM in response to Fios89

I think your book (which is the C book to have, by the way) combined with Brian's instructions on how to use GCC in the Terminal, should be good to get you started. That book isn't going to teach you how to do anything dangerous and would be a good knowledge to have. So I think you are on the right track. I apologize if I've started an unproductive tangent.

GCC for OS X

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.