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

Similar Threads
thread Thread Starter Forum Replies Last Post
Seeking an images-to-video compiler Morgan Stack Mac Applications and Mac App Store 4 Dec 31, 2013 11:18 PM
Where is my gcc and g++ compiler sysProgrammer Mac Programming 10 Nov 24, 2013 06:47 PM
Moving from xcode 3.2 to xcode 4.5.2 compilation error for 'abs' macro in stdlib.h hrishidev Mac Programming 7 Jun 2, 2013 10:36 AM
Assembly Compiler/IDE SuperMiguel Mac Programming 7 Jun 23, 2012 05:36 PM
Broken C compiler dancks Mac Programming 2 Jun 15, 2012 03:04 PM

Forum Jump

All times are GMT -5. The time now is 07:23 PM.

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

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