Xcode includes command line development tools such as gcc and friends.
Step #1: Install Xcode
First, make sure Xcode is installed. If it is not installed on OS X, visit app store and install Xcode.
Step #2: Install gcc/LLVM compiler
Once installed, open Xcode and visit:
Xcode menu > Preferences > Downloads > choose "Command line tools" > Click "Install" button:
Xcode will download package and install copies of the core command line tools and system headers into system folders, including the LLVM compiler, linker, and build tools.
Step #3: Verification
Open a terminal and type the following commands:
$ gcc --version
$ whereis gcc
$ whereis make
Sample outputs:
Testing sample "Hello world" C program
Create a text file called a.c as follows using a text editor such as vi or cat command:
/* a.c - demo for os x */ #include<stdio.h> int main(void){ printf("Hello world\n"); return 0; }
To compile, enter:
$ make a
Run it as follows:
$ ./a
Sample outputs:
SEE ALSO
And, there you have it, the gcc version 4.2.1 installed and working correctly on the latest version of Mac OS X 10.8.4. In Apple's version of GCC, both cc and gcc are actually symbolic links to the llvm-gcc compiler. Similarly, c++ and g++ are links to llvm-g++. For more information and examples see the following man pages:
$ man gcc
$ man make