Beginner Compiler

Discussion in 'Mac Programming' started by Melkor, Feb 10, 2006.

  1. macrumors 6502

    Joined:
    Oct 12, 2005
    #1
    So I just started doing a bit of c programming in college and am having a bit of trouble.

    I want to be able to do my homework assignments on my powerbook, but I can't seem to figure out how xcode works.

    So I'm looking for a more basic compiler where I can just type in my code and click build. (Like a mac version for the Dev compiler)

    All we're doing is building very basic programms, like pinting out the Fibonacci series and converting farenheit to celcius, so I just need something very simple.

    Thanks a lot :)
     
  2. Moderator emeritus

    Mitthrawnuruodo

    Joined:
    Mar 10, 2004
    Location:
    Bergen, Norway
    #2
    The best would probably be to download a nice, free text editor, like TextWrangler. Write your code in that and compile and run via Terminal...

    Make a file with the code, name it file.c. Open Terminal use cd to get to the directory (folder) where the file is.
    Compile with gcc -o program file.c
    And run it with ./program

    Of course you can use other names for your file and executable... ;)
     
  3. macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    chicago
    #3
    damn, i thought from the thread title that the OP was going to write his own compiler. i was hoping we'd be talking about token generators and such.
     
  4. thread starter macrumors 6502

    Joined:
    Oct 12, 2005
    #4

    That's just what I wanted. Thanks a lot man.
     
  5. macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #5
    Also, using gcc directly like that is a great way to learn. You'll use it for a while and then when you're ready to switch to Xcode, you'll understand what it's doing under the hood--exactly what you've been doing by hand.
     
  6. macrumors 65816

    GilGrissom

    Joined:
    Mar 13, 2005
    #6
    Hey guys.

    Sorry to sound stupid here, but I'm in pretty much the exact same position as the OP.

    I tried that gcc command in the terminal, but it says "command not found". What stupid thing am I doing wrong here?

    Any help would be appreciated!
     
  7. Moderator emeritus

    Mitthrawnuruodo

    Joined:
    Mar 10, 2004
    Location:
    Bergen, Norway
    #7
    Have you installed Developer Tools?
     
  8. macrumors 65816

    GilGrissom

    Joined:
    Mar 13, 2005
    #8
    From the XCode folder?
     
  9. Moderator emeritus

    Mitthrawnuruodo

    Joined:
    Mar 10, 2004
    Location:
    Bergen, Norway
    #9
    Yes...? Is it called that, and not Developer Tools?
     
  10. macrumors 65816

    GilGrissom

    Joined:
    Mar 13, 2005
    #10
    Theres a Developer Tools package inside the XCode folder in Applications.


    UPDATE:

    I've installed the "DeveloperTools.pkg" file under "Installers>XCode Tools>Packages"...still nothing, still get "Command not found" when I try and run gcc under terminal.
     
  11. Moderator emeritus

    Mitthrawnuruodo

    Joined:
    Mar 10, 2004
    Location:
    Bergen, Norway
    #11
    Did you restart (or at least log out and back in) after installing Developer Tools?
     
  12. macrumors 65816

    GilGrissom

    Joined:
    Mar 13, 2005
    #12
    Ye...total reboot, still no luck!

    Theres gotta be something really stupid and silly that I simply haven't done or something!

    Thanks for your help.

    Any ideas?
     
  13. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #13
    It sounds like somehow your Terminal path environment variable doesn't include the path where gcc lives.

    type set (or setenv) and see what PATH is.

    B
     
  14. macrumors 65816

    GilGrissom

    Joined:
    Mar 13, 2005
    #14
    "set" has revealled:

    PATH=/bin:/sbin:/usr/bin:/usr/sbin
     
  15. macrumors 603

    gekko513

    Joined:
    Oct 16, 2003
    #15
    Is that the main Xcode installer? If it isn't and you haven't installed Xcode, you could try to install the whole thing.
     
  16. macrumors 65816

    GilGrissom

    Joined:
    Mar 13, 2005
    #16
    I have no idea! This is my first experience with XCode on any level!

    I've found an XCode Tools.pkg installer just inside the XCode Installer folder, see if this herralds some promising results!
     
  17. Moderator emeritus

    yellow

    Joined:
    Oct 21, 2003
    Location:
    Portland, OR
    #17
    gcc should be in /usr/bin/, so since it's in your path, it's probably not installed ("which gcc" will tell you). You should get the latest version of XCode tools from the Apple developer website (http://developer.apple.com). It's free to sign up, and it's free to download. But it's VERY larger. 800+MB I believe, so prepare for that.

    xcode_2.2.1.dmg

    Once you have the DMG downloaded, you double click the XcodeTools.mpkg to install it.
     
  18. macrumors 6502

    Joined:
    Aug 2, 2002
    Location:
    Éire
    #18
    Just install the full Xcode tools and restart. Gcc should work fine then.
     
  19. macrumors 65816

    GilGrissom

    Joined:
    Mar 13, 2005
    #19
    That XCode Tools.pkg I just found has now given me gcc. Thanks guys!

    How out of date will my XCode be and will it affect compiling basic C at all?

    (Im supposed to get it to compile on a Unix box at uni, but cannot access it from home, so Im compiling it on my PowerBook and then I'll do any minor debugging when I'm on site at uni when I have access to the Unix box.)

    Is it worth me getting the very latest XCode or just sticking with what I already have? (OS X 10.4.5)

    Thanks guys for your help!
     
  20. macrumors 603

    gekko513

    Joined:
    Oct 16, 2003
    #20
    For just using gcc for a uni course I don't think it would make any difference.
     
  21. Moderator emeritus

    yellow

    Joined:
    Oct 21, 2003
    Location:
    Portland, OR
    #21
    wasn't there a bug in earlier version of gcc4? AH, it was gcc3. From the Dev site:

    Don't know if this is effect you or not.

    I just want to make sure GG doesn't get screwed somewhere along the way trying to find a bug that isn't in his code.
     
  22. macrumors 65816

    GilGrissom

    Joined:
    Mar 13, 2005
    #22
    Any debugging I do is only to make sure that my Mac compiler hasn't used any special items that are different to what the Unix compiler on the uni server would use (e.g.: we've been told to avoid using Windows as it will compile slightly differently and add things that the Unix box cannot compile.) We can write and compile the code on whatever we want but have to demo the code compiling and running on the Unix box come the hand-in date. (confused?...I sure am!)

    Sorry if this is slightly off topic now, but do you happen to know how different, if there is any difference, the Mac OS X gcc compiler is to the compiler that this Unix box will have? Don't worry if you don't know, I'm just curious. Sorry I don't have any Unix version numbers or anything, it's just a Compaq box with Unix on it! Am I right in saying there shouldn't be much difference at all, being as OS X is based on Unix?

    I know it shouldn't matter anyway as I doubt I'll be using any special things that are unique to certain compilers anyway, so it should run fine regardless.

    But anyway, thanks for all your help guys! You've all been invaluable!!

    (Yey I can now compile C on my Mac!...gutted I have to do C in the first place! lol!)
     
  23. macrumors 603

    gekko513

    Joined:
    Oct 16, 2003
    #23
    For strict ANSI-C it should be identical, but if you start doing things with system(...) or include platform specific C-libraries like glibc or similar, there can be differences.
     
  24. Moderator emeritus

    yellow

    Joined:
    Oct 21, 2003
    Location:
    Portland, OR
    #24
    What gekko said. For all intents and purposes the gcc on the Mac will be the same on another flavor of UNIX. Different libraries may apply, and as gekko said, hardware specific code will certainly be different. But all in all, it's just a GNU C Compiler.
     
  25. mstriker, Oct 13, 2011
    Last edited by a moderator: Oct 13, 2011

    macrumors newbie

    Joined:
    Jul 15, 2011
    #25
    Just wanted to thank you for your answer. Indeed it worked. I am self-studying C and wanted a compiler for my iMac to run programs. Had no idea where to begin.
    1. Installed xCode ver 3.2.3. from the app-CD that came with the iMac. Tested gcc in the terminal line - the command was recognized.
    2. Downloaded TextWrangler from BareBones website and installed.
    3. Created a hello.c simple file and saved it on the Desktop
    4. Changed directory by typing in the terminal window cd Desktop. Made sure the file was there by typing ls, it was.
    5. Compiled the file and run the executable.

    Thanks man for the guidance. I can practise now!!!!
     

Share This Page