C problem

Discussion in 'Mac Programming' started by JD92, Aug 16, 2005.

  1. JD92 macrumors 6502a

    JD92

    Joined:
    Apr 14, 2005
    #1
    Hi, I'm trying to learn C. I compile the Hello World program in gcc from the terminal and it produces a file called 'a.out', but when I click on the file, it just says theres no program assosciated to .out files :confused:

    Any hints?

    Thanks
     
  2. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #2
    Using the command-line "gcc" compilation tool does not produce a double-clickable, executable file (by default, anyway). In Terminal, if you navigate to the same directory where your executable lives, you can run it by typing:
    Code:
    ./a.out
    or from another directory with the full path:
    Code:
    /Users/<someuser>/<somedirectory>/a.out
    I use Xcode to produce double-clickable applications, there's probably a way to do that from the command-line (since Xcode calls gcc "under the coves") but it may be complicated. Try using Xcode.
     
  3. JD92 thread starter macrumors 6502a

    JD92

    Joined:
    Apr 14, 2005
    #3
    I can't believe I didnt think of that, thanks!

    Anyway, when I double click on Hello.c, it brings up the code in the XCode window, but I can't figure out how to compile it from XCode. I thought maybe go to 'Build', but everything in the 'Build' menu is greyed out, so I can't click anything.
     
  4. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #4
    Yeah, you need to have your source files in a project to compile them in Xcode. Choose New Project from the File menu and if you're just using straight ANSI C, choose the Standard Tool project type. Add your source code to the main.c file in the project, then Command-B to build it, or Command-R to build and run it in Xcode. To run it external of Xcode, you can find a double-clickable file in the <project folder>/build/Debug folder which will launch Terminal and run it inside that.

    However, I must warn you that while Xcode is an excellent development environment, it can be vastly complicated to use, especially if you are new to programming. If you're just starting out, I'd recommend keeping it simple by using TextWrangler to edit your source code and using Terminal to compile and run it. Becoming familiar with Terminal will benefit you in the future as a programmer no matter what IDE you choose later as your projects become more complex.
     
  5. JD92 thread starter macrumors 6502a

    JD92

    Joined:
    Apr 14, 2005
    #5
    OK, I'll give it a shot.

    And I'll try TextWrangler.

    And I know how to use the Terminal a little bit, stuff like ls, cd, pwd, wildcards etc.
     

Share This Page