Mac OS X: Install GCC Compiler with Xcode

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.

Fig.01: Make sure Xcode developer tools are install OS X

Fig.01: Make sure Xcode developer tools are install OS X

Step #2: Install gcc/LLVM compiler

Once installed, open Xcode and visit:

Xcode menu > Preferences > Downloads > choose "Command line tools" > Click "Install" button:

Fig.02: Installing gcc compiler on Mac OS X

Fig.02: Installing gcc compiler on Mac OS X


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:

Fig.03: Verify gcc compiler installation on Mountain Lion OS X

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:

Fig.04: Compiling and running sample

Fig.04: Compiling and running sample "Hello world" C program on Mountain Lion 10.8.4

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值