Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I compile a .c file on my Mac?

Tags:

c

macos

How do I compile a .c file on my Mac?

like image 828
David Avatar asked Apr 08 '10 21:04

David


2 Answers

You'll need to get a compiler. The easiest way is probably to install XCode development environment from the CDs/DVDs you got with your Mac, which will give you gcc. Then you should be able compile it like

gcc -o mybinaryfile mysourcefile.c 
like image 180
OndraSej Avatar answered Sep 20 '22 20:09

OndraSej


You will need to install the Apple Developer Tools. Once you have done that, the easiest thing is to either use the Xcode IDE or use gcc, or nowadays better cc (the clang LLVM compiler), from the command line.

According to Apple's site, the latest version of Xcode (3.2.1) only runs on Snow Leopard (10.6) so if you have an earlier version of OS X you will need to use an older version of Xcode. Your Mac should have come with a Developer Tools DVD which will contain a version that should run on your system. Also, the Apple Developer Tools site still has older versions available for download. Xcode 3.1.4 should run on Leopard (10.5).

like image 27
Adam Batkin Avatar answered Sep 18 '22 20:09

Adam Batkin