Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 18, 2011, 05: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, 06:02 PM   #2
talmy
macrumors 601
 
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 Yosemite Server, 5 other Macs and an unused Apple TV in the household.
talmy is offline   0 Reply With Quote
Old Oct 19, 2011, 04: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, 05: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, 11:54 AM   #5
talmy
macrumors 601
 
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 Yosemite Server, 5 other Macs and an unused Apple TV in the household.
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

Similar Threads
thread Thread Starter Forum Replies Last Post
Mac programming should be more like iOS programming. moonman239 Mac Programming 13 Feb 17, 2014 02:37 PM
General: FIX "Error opening terminal: xterm-256color" for Terminal Commands (e.g., "top") iOS7 thelatinist Jailbreaks and iOS Hacks 9 Jan 10, 2014 08:46 PM
Terminal terminal-ology geohump Mac Applications and Mac App Store 0 May 17, 2013 01:40 PM
New to Programming swimanole Mac Programming 10 Nov 6, 2012 12:55 PM
Programming Outside The Terminal jamesadrian Mac Programming 9 Sep 27, 2012 05:12 AM

Forum Jump

All times are GMT -5. The time now is 11:50 AM.

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

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