Compile a C file in XCode

Moderator
Posts: 623
Joined: 2007.09
Post: #1
I am looking at a C tutorial, and was wondering if there is a way to compile a C file inside xCode, instead of using Terminal. My procedure is;
1. Create a new empty file
2. Save it as hello.c (For this specific problem)
3. Type in my code
4. And I can't find any "Compile" or "Run" etc button.

Any suggestions?

Maybe I need to create empty file in new project?

Thanks in advance…

Lincoln Grrrrrrreen a.k.a C newbie
Quote this message in a reply
Member
Posts: 245
Joined: 2005.11
Post: #2
I'm assuming you're building a "Hello world" type terminal program...

Run Xcode, select "New Project". Select "Standard Tool" from the "Command Line Utility" section.
Your new project will contain a file called "main.c" - put your code in there.
Click the hammer icon to build, or the hammer icon with the green circle/play button to "build and run".
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #3
OK, thanks alot!Smile
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #4
There's Something interesting. Before I read your post, I put a file named hello.c in my home folder. I then put my code in there. After I read your post, I did what you said and put an xCode project called "hello" in the same folder, and it loaded my code into main.c. Very Cool!!!Cool
Quote this message in a reply
Member
Posts: 20
Joined: 2006.06
Post: #5
Hairball183 Wrote:There's Something interesting. Before I read your post, I put a file named hello.c in my home folder. I then put my code in there. After I read your post, I did what you said and put an xCode project called "hello" in the same folder, and it loaded my code into main.c. Very Cool!!!Cool
Are you certain that your hello world example was't just the same as Apple's default hello world?
Quote this message in a reply
Member
Posts: 59
Joined: 2007.12
Post: #6
As your question has already been answered... why do you prefer building with XCode? IMHO, it's easier to maintain a makefile for most smaller projects, certainly for a "Hello World" program.
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #7
My workflow before was,
1. Make a new empty file
2. type in my code
3. build in terminal
4. Run from Terminal

I used this for HTML and Java, so now I'm using it with C, only I'm using a project instead of a empty file. As for why I don't maintain a makefile…
1. I'm happy with xCode
2. I don't know how
3. I don't really see a reason to figure out how, since I use xCode.

Is there an advantage to makefile over xCode?
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #8
kordova Wrote:Are you certain that your hello world example was't just the same as Apple's default hello world?

Yes, actually it was, with several minor differences. It did not load in my code after all. In fact, I wrote a post to that effect before I saw your post, but for some reason it didn't get posted.Ninja
Quote this message in a reply
Apprentice
Posts: 6
Joined: 2007.10
Post: #9
Hi,
I'm learning programming languages (obj-c now, c++ then) and I'm using xcode to write my code, but I don't want to make a new project for every new exercise or test I do. I'd like to be able to add new .m files at will in only one project (to say Obj-C exercises project) and then compile and run only one source file at time. Is there a way to do it?

Thanks
Quote this message in a reply
Moderator
Posts: 623
Joined: 2007.09
Post: #10
I think you can do that by unchecking the little checkbox next to the file you don't want to build. But, I'm no expert.Rolleyes
Quote this message in a reply
Apprentice
Posts: 6
Joined: 2007.10
Post: #11
Yes it works, thanks
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Can I rig up xCode to compile simple .exe's? Jones 14 6,376 Jan 10, 2006 06:25 AM
Last Post: dair
  Xcode debugger and C++ global/file scope variables. WhatMeWorry 2 4,917 Sep 9, 2005 12:34 AM
Last Post: WhatMeWorry