Mac C problem

JD92

macrumors 6502a
Original poster
Apr 14, 2005
934
31
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
 

HiRez

macrumors 603
Jan 6, 2004
5,851
1,812
Western US
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.
 

JD92

macrumors 6502a
Original poster
Apr 14, 2005
934
31
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.
 

HiRez

macrumors 603
Jan 6, 2004
5,851
1,812
Western US
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.
 

JD92

macrumors 6502a
Original poster
Apr 14, 2005
934
31
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.