Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | Yes |
Requirements | Mac OS X Mountain Lion |
Time | Depends on the internet speed |
Step #1: Install Xcode on a Apple Mac OS X
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 on OS X
Once installed, open Xcode and visit:
Xcode menu > Preferences > Downloads > choose "Command line tools" > Click "Install" button:
Step #3: Verification
Open a terminal app 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
- Ubuntu Linux Install GNU GCC Compiler and Development Environment
- Debian Linux Install GNU GCC Compiler and Development Environment
- CentOS / RHEL 7: Install GCC (C and C++ Compiler) and Development Tools
- Download and Install C, C++ Compiler on Red Hat Enterprise Linux 5 (RHEL)
- Mac OS X: Install GCC Compiler with Xcode
- Where is My Linux GNU C or GCC Compilers Are Installed?
- HowTo: Compile And Run a C/C++ Code In Linux
- RHEL / CentOS Linux Install Core Development Tools Automake, Gcc (C/C++), Perl, Python & Debuggers
- HowTo Compiling C Program And Creating Executable File Under a Linux / UNIX / *BSD
- How To Install ncurses Library on a Linux
- Linux Find Out What Compilers Are Installed or Available On The System
- Linux Find Out GNU gcc Compiler Version Used To Compile Running Kernel
- Howto see output of C program in Linux or UNIX
🐧 28 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
There is no need to install huge xcode consumes gigabytes of disk space (if you are not a apple developer), just go to the apple’s developer page and download the “command line tool for xcode” package and install it, that would be just sufficient.
Isn’t GCC is LLVM with GCC support and many automake, m4 etc… project is not enable to build.
thank u very very very much you are really clever
THANK YOU SO MUCH!!! Everything else I tried didn’t seem to work. Finally this did!!!!
Thank you very much. It worked.
I installed the Xcode Command Line Tools, and when I try to find gcc in the terminal
tell me this:
new-host:~ asaffeldman$ $gcc –version
-bash: –version: command not found
?? help
try:
with 2 dashes and no $ in front of it
hope it helps!
I anderstand
Clear , efficient , thanks !
I have GCC 4.8.1 with x86, x86_64 and PPC on Lion with ObjC, C/C++11, Fortan, Ada Go support.
And now I can compile PHP, WxWidgets, QT and many other source without problems like on Apple Clang vesion. In xcode too.
Gcc builded with llvm-gcc-4.2.
i m doing the c programming on terminal my keyword is not highlited by compiler,
strstr function is not working why plz resolve my problm
hi
when I typed make a I got this message:
make: *** No rule to make target `a’. Stop.
please help me.
Thanks.
I got the same error when I didn’t spell the filename with the exact case.
Hi , I installed xcode and command line tools just as you said but when I try the command gcc –version I get this error
Error: could not stat active Xcode path ‘/Volumes/Xcode/Xcode.app/Contents/Developer’. (No such file or directory)
Is my xCode in the wrong place? It’s installed and under Applications, please help
I AM GETTING THIS ERROR IN XCODE WHILE I AM BUILDING A PROGRAM IN C++
I don’t have the Command Line option in my preference. Help!
I have xcode. I see gcc on my mac: Macintosh/Developer/usr/bin/gcc-4.0
But as soon as I type gcc whatever in the terminal because I want to compile a file called hpgl2eagle1.c to be able to use it, it outputs an error: gcc command not found.
Set PATH variable on your OS X. See: “Mac OS X: Set / Change $PATH Variable” for more info.
It worked. Thank you very much!
Does it work on Mac air?
Yup.
i can’t find command line tools on my xcode. >< my xcode version is 6.3.2
Open the Terminal app and cd to /Applications/Xcode.app/ path:
cd /Applications/Xcode.app/
HELP; In the downloads, I don’t see command line tools.
Please help
i have the x-code and when i typed gcc –version it gave
‘Configured with: –prefix=/Applications/Xcode.app/Contents/Developer/usr –with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin14.5.0
Thread model: posix’
and when i type ls -l /usr/bin/gcc
‘-rwxr-xr-x 1 root wheel 14160 Sep 28 2014 /usr/bin/gcc’
so i cant go beyond this. Can someone please help?
Hi nixCraft,
this advice helped a lot.
thank you very much
After you type:
/*
$ where is make
/usr/bin/make
Manny -MBP:~ Manny$ []
*/
the 3rd line comes out again….I would like to know what do you type next to start creating your source code?