Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Nov 15, 2011, 02:28 PM   #1
v2club
macrumors regular
 
Join Date: Apr 2011
Can I use Xcode as a C compiler?

I'm reading a book about C programming language (C for dummies) since I have no clue about programming what so ever and couldn't find a book about Objective C for absolute beginners, in all the books for Objective C says that I have to have a basic knowledge and understanding about programming (which I don't have). Anyway in order to start practice I need a compiler, in the book says that there is a built in compiler in the Mac OS X, but I was wandering whether I can use Xcode and how exactly? I mean when I go to New Project, where do I click next and what do I do exactly?
v2club is offline   0 Reply With Quote
Old Nov 15, 2011, 04:01 PM   #2
lloyddean
macrumors 6502a
 
Join Date: May 2009
Location: Des Moines, WA
Xcode is itself a nexus point for managing. editing, linking and debugging code.

Installing Xcode will install a compiler, linker and debugger amongst other things.
lloyddean is offline   0 Reply With Quote
Old Nov 15, 2011, 04:05 PM   #3
v2club
Thread Starter
macrumors regular
 
Join Date: Apr 2011
Quote:
Originally Posted by lloyddean View Post
Xcode is itself a nexus point for managing. editing, linking and debugging code.

Installing Xcode will install a compiler, linker and debugger amongst other things.
OK so when in the book says type something in the compiler, where do I click and how do I open it?
v2club is offline   0 Reply With Quote
Old Nov 15, 2011, 04:12 PM   #4
lloyddean
macrumors 6502a
 
Join Date: May 2009
Location: Des Moines, WA
You can't type things into a compiler.

Source code is typed into, and modified with, a text editor then saved into a file with a .c extension and then compiled with a compiler.

Does the book you have have a section on compiling code on a Mac?
lloyddean is offline   0 Reply With Quote
Old Nov 15, 2011, 04:24 PM   #5
lloyddean
macrumors 6502a
 
Join Date: May 2009
Location: Des Moines, WA
It'd most likely be in an Appendix near the back of the book.
lloyddean is offline   0 Reply With Quote
Old Nov 15, 2011, 04:24 PM   #6
v2club
Thread Starter
macrumors regular
 
Join Date: Apr 2011
Yes but I haven't read that far , I'm in the beginning where it says that I need a compiler and that there is built-in one in the Mac OS X, but I was thinking it would be good Idea to get used to the Xcode...
v2club is offline   0 Reply With Quote
Old Nov 15, 2011, 04:30 PM   #7
lloyddean
macrumors 6502a
 
Join Date: May 2009
Location: Des Moines, WA
Are you good a learning three or four things at a time?

----------

Why don't you try following something like this Xcode Tutorial on YouTube.
lloyddean is offline   0 Reply With Quote
Old Nov 15, 2011, 05:39 PM   #8
mduser63
macrumors 68040
 
mduser63's Avatar
 
Join Date: Nov 2004
Location: Salt Lake City, UT
Send a message via AIM to mduser63
To directly answer your question: Yes, you most definitely can use Xcode to write and compile C code.

That out of the way, if you're going to learn C, at least while you're just getting started, I'd say it's a good idea to learn how to use gcc from the command line. It's actually simpler than something like Xcode for small programs, and you'll get a better idea of the steps involved in building a program. The essential procedure is:

Type your program into a text editor (TextEdit comes with Mac OS X, and will work). Save the program as a plain text file with the extension ".c". Here's a really simple program:

Code:
#include <stdio.h>

int main(int argc, char* argv[])
{
   printf("Hello World!\n");
   return 0;
}
After you've done that, open Terminal (in /Applications/Utilities), and at the prompt type something like:

gcc /path/to/your/program/yourprogram.c -o program

Where "/path/to/you/program/' is the path to your .c file, "yourprogram.c" is the name of the file you saved with your text editor and "program" is the name you want your program to have after it's compiled.

GCC will compile your program, or give you information about errors in your source code if there are any. Assuming no errors, it will create an executable file, which you can run by typing:

./program

(replacing "program" with the name you put after "-o" in the gcc command above).

If it works, you'll see something like

$>./hello
Hello World!
$>

The easiest way to get GCC is indeed to install Xcode, which includes GCC. You can get Xcode on the Mac App Store.
mduser63 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Learning how to use Xcode / interface builder to program in c/++ furycd001 Mac Programming 6 Sep 20, 2011 04:45 AM
Xcode 4 and non-C compilers mbarriault Mac Programming 3 Aug 6, 2011 06:51 PM
Can I use timecapsule as an external hd as well as with timeamachine macgrl Mac Basics and Help 32 Mar 12, 2011 02:33 PM
Can u use iPhone as a Harddrive ? fab5freddy iPhone 14 Apr 17, 2009 05:31 PM
Can you use it as an iPod without needing to do a credit check etc? AVR2 iPhone 1 Jun 30, 2007 04:07 AM


All times are GMT -5. The time now is 11:54 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC