Skip navigation
This discussion is archived

GCC for OS X

2432 Views 18 Replies Latest reply: Jul 12, 2008 4:45 PM by Alonso Delarte RSS
1 2 Previous Next
Fios89 Level 1 Level 1 (5 points)
Currently Being Moderated
Apr 16, 2008 11:57 AM
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)
  • Brian Postow Calculating status...
    Currently Being Moderated
    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
    Mac Mini, Mac OS X (10.5.1)
  • Tod Kuykendall Level 4 Level 4 (2,270 points)
    Currently Being Moderated
    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
    G5/2.0x2, Dual XServes x2, XRAID, beige G3 501Mhz
  • xnav Level 5 Level 5 (6,615 points)
    Currently Being Moderated
    Apr 16, 2008 1:21 PM (in response to Fios89)
    Install the Developer Tools, then follow [this|http://discussions.apple.com/thread.jspa?messageID=6753372] to get started.
    Mac Pro 2x3GHz Dual, Mac OS X (10.5.2), BootCamp WinXP, LinkSys WRT54G, iPhone, AppleTV
  • etresoft Level 7 Level 7 (23,870 points)
    Currently Being Moderated
    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?
    MacBook, Mac OS X (10.5.2), 1.83Ghz/2GB Ram/160 HD et al.
  • Brian Postow Level 1 Level 1 (40 points)
    Currently Being Moderated
    Apr 16, 2008 2:14 PM (in response to Fios89)
    The odds of C being less confusing than java are slim, in my opinion... they basically have the same syntax. Java has more complicated data structures, but to a beginner, they look pretty much the same...

    Having taught both, I can say that Java is easier to teach, without a question, but YMMV.
    Mac Mini, Mac OS X (10.5.1)
  • xnav Level 5 Level 5 (6,615 points)
    Currently Being Moderated
    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.
    Mac Pro 2x3GHz Dual, Mac OS X (10.5.2), BootCamp WinXP, LinkSys WRT54G, iPhone, AppleTV
  • Brian Postow Level 1 Level 1 (40 points)
    Currently Being Moderated
    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."
    Mac Mini, Mac OS X (10.5.1)
  • etresoft Level 7 Level 7 (23,870 points)
    Currently Being Moderated
    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.
    MacBook, Mac OS X (10.5.2), 1.83Ghz/2GB Ram/160 HD et al.
1 2 Previous Next

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.