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 Oct 18, 2011, 04:51 PM   #1
manee
macrumors newbie
 
Join Date: Sep 2011
c programming on terminal

can someone please tell me how to write and compile a c program in terminal. i use xcode and don't really like it.
manee is offline   0 Reply With Quote
Old Oct 18, 2011, 05:02 PM   #2
talmy
macrumors 68040
 
talmy's Avatar
 
Join Date: Oct 2009
Location: Oregon
Edit the file with any text editor (I'm an emacs fan myself, but most people like vi and there is also nano and probably others). Compile with the gcc command.

Example:
yourfavoriteeditor hello.c
gcc -o hello hello.c
./hello
__________________
27" i7 iMac, 15" MacBook Pro, Mac mini with Mavericks Server, 5 other Macs and an Apple TV.
talmy is offline   0 Reply With Quote
Old Oct 19, 2011, 03:02 AM   #3
briankkatz
macrumors newbie
 
Join Date: Oct 2011
Location: 5220 Summer Cres, Virginia Beach, VA 23462
Send a message via Yahoo to briankkatz
Editing will work and you will get some related detailed information here:

http://osxbook.com/book/bonus/ancien...ogramming.html
http://www.daniweb.com/software-development/
__________________
Christian healing app
briankkatz is offline   0 Reply With Quote
Old Oct 19, 2011, 04:57 AM   #4
cqexbesd
macrumors member
 
Join Date: Jun 2009
Quote:
Originally Posted by talmy View Post
Compile with the gcc command.
There is nothing wrong with gcc but can I recommend you try out clang as well. The usage is almost identical but as a new user you might find the warnings and errors a bit easier to deal with. You should try turning on some extra warnings as well so the compiler gives you some hints about possible errors. So instead of:

Quote:
Originally Posted by talmy View Post
gcc -o hello hello.c
try:

clang -Wall -o hello hello.c
cqexbesd is offline   1 Reply With Quote
Old Oct 19, 2011, 10:54 AM   #5
talmy
macrumors 68040
 
talmy's Avatar
 
Join Date: Oct 2009
Location: Oregon
Yep, use Clang. I had replied with the "generic answer" but have been using Clang myself. Superior error and warning messages wrt GCC.

I'll also add that anyone spending any time compiling from the command line should learn to use make. Every C program I work on (and there are lots) is built using make.
__________________
27" i7 iMac, 15" MacBook Pro, Mac mini with Mavericks Server, 5 other Macs and an Apple TV.
talmy 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
Accessing Blocked Programs on Mac, such as terminal TheAshAtomic Mac Applications and Mac App Store 20 Mar 8, 2011 05:19 PM
running c program in Terminal rmumma2 Mac Programming 6 Mar 15, 2008 06:53 PM
Running C programs on the terminal s1587 Mac Programming 8 Nov 18, 2007 04:02 AM
Problem in compiling a C program in terminal uipe Mac Programming 5 Nov 13, 2007 04:12 PM
secure delete program for terminal superbovine Mac Applications and Mac App Store 0 Mar 28, 2004 12:35 AM


All times are GMT -5. The time now is 02:09 PM.

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

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