PDA

View Full Version : How to program in C on Mac without using XCode




luckydev
Sep 8, 2010, 05:55 AM
Hi,

I have just come to Mac world from Linux world and I love my way around in Mac environment. I want to write and practice simple C programs in mac and I was searching for the tools I require. Most (All) of the resources in the web ask me to use XCode as IDE to do programming in C on Mac. XCode, for my purpose seems to be an overkill. I am in no way interested in developing iPhone or Mac GUI application. All I want is

enter C programs using a text editor,
compile it ,
and get the output in a Console.
How can I do it ?

Thanks.



MorphingDragon
Sep 8, 2010, 06:03 AM
Hi,

I have just come to Mac world from Linux world and I love my way around in Mac environment. I want to write and practice simple C programs in mac and I was searching for the tools I require. Most (All) of the resources in the web ask me to use XCode as IDE to do programming in C on Mac. XCode, for my purpose seems to be an overkill. I am in no way interested in developing iPhone or Mac GUI application. All I want is

enter C programs using a text editor,
compile it ,
and get the output in a Console.
How can I do it ?

Thanks.

The version of GCC for mac comes with XCode. Install xcode, then call gcc form the terminal just like in Linux.

Hansr
Sep 8, 2010, 07:51 AM
Or grab the GCC binaries from here:
http://hpc.sourceforge.net/

Then you can compile directly with text editor + terminal.

I recommend XCode thought just for easier (visual) debug + code sense (intellisense, what ever their calling it this week) which will generally speed coding.

willieva
Sep 8, 2010, 11:15 AM
Install xcode to get gcc

vi/emacs are already on your computer

It's just like any other unix computer with bash/csh

robvas
Sep 10, 2010, 11:18 PM
Documents robert$ nano hello.c
Documents robert$ gcc hello.c
hello.c: In function ‘main’:
hello.c:4: warning: return type of ‘main’ is not ‘int’
Documents robert$ ./a.out

Welcome to Mac OS X
Documents robert$


If you type "gcc -o hello hello.c" it will make 'hello' the program, the default is 'a.out'

Nano is just a simple text editor (free alternative to pico, the pine editor)

subsonix
Sep 11, 2010, 06:43 PM
Seems like you've got a 'void main' going on there. :p

Cromulent
Sep 11, 2010, 07:35 PM
Seems like you've got a 'void main' going on there. :p

EVIL!

robvas
Sep 11, 2010, 07:37 PM
Seems like you've got a 'void main' going on there. :p

Hey, he didn't ask for programming lessons! He's on his own for that.

gnasher729
Sep 12, 2010, 05:36 AM
Hi,

I have just come to Mac world from Linux world and I love my way around in Mac environment. I want to write and practice simple C programs in mac and I was searching for the tools I require. Most (All) of the resources in the web ask me to use XCode as IDE to do programming in C on Mac. XCode, for my purpose seems to be an overkill. I am in no way interested in developing iPhone or Mac GUI application. All I want is

enter C programs using a text editor,
compile it ,
and get the output in a Console.
How can I do it ?

Thanks.

Just one thing: If you have any programming questions and ask here for help, please state very very clearly that you are not using XCode. Lots of times people will ask what error message XCode gives, ask you to set a breakpoint somewhere and so on, and if you don't use XCode then this is all a waste of time. In particular I wouldn't want to waste my time giving help on a problem that is caused by some compiler options that would never have happened if you had started out with the XCode templates.

In other words: Go with the flow.

MorphingDragon
Sep 13, 2010, 03:17 AM
Just one thing: If you have any programming questions and ask here for help, please state very very clearly that you are not using XCode. Lots of times people will ask what error message XCode gives, ask you to set a breakpoint somewhere and so on, and if you don't use XCode then this is all a waste of time. In particular I wouldn't want to waste my time giving help on a problem that is caused by some compiler options that would never have happened if you had started out with the XCode templates.

In other words: Go with the flow.

I have to disagree, going with the flow means to use Visual Studio for C++ and thats just not on. ;)

---

Xcode has a commandline app template, use it.