Меню Рубрики

Установка gcc на mac

How to install gcc compiler on Mac OS X

Often times, you need c or gcc compiler to compile open source projects in Mac OS X. The problem is Mac OS X doesn’t install the gcc compiler by default.

If you try to install or compile some projects that required c/gcc compiler, following errors message will be logged :

In terminal, type “ gcc “, you will get message “command not found”.


To install gcc compiler on Mac OS X, you need to download and install “Command Line Tools for Xcode”, which is available in Apple’s developer page. See following steps :

1. Register Apple Developer Account

Access Apple’s developer page, to process on the download, you need to register an Apple account, it’s free, but need to spend few minutes to fill in the survey.

2. Command Line Tools for Xcode

In Apple developer page, “Developer Tools” category, find “Command Line Tools for Xcode“, choose your version and click on the xx.dmg file (file size is 100mb ++) to start the download.

3. Installation

After .dmg file is downloaded, a small dialog will be prompted and show you this file – “Command Line Tools.mpkg“, just double click on it, follow the wizard guide to complete the installation.

4. Verification

After installation is completed, run “ gcc -v ” in terminal again. If everything fine, following output will be displayed.

Done, the gcc version 4.2.1 is installed on Mac OS X successfully.



Oh for * sake. I wanted to install GCC, not xcode! FYI, xcode is not gcc. Also, xcode doesn’t contain gcc, but LLVM. There is slight, but definite difference.

One good approach to work with GCC in mac is to install docker and run a container with GCC and mount a directory with the container. That’s it

i just followed your instructions above and downloaded the command line tools for xcode
ran the gcc -v command….everything ok but
im trying to compile a simple c++ test program but getting error:

“no such file or directory”

Should be gcc function.php

Awesome man thanks. Macbook osx 10.9

So the thuglife gangster terrorist scum at macintrash are in material violation of the GPL? Nice to know. Do they also work with Al Qaeda in Lebanon (Fatah al Islam, Asbat Al Ansar), Libya (Al Qaeda in North Africa Benghazi, Al Qaeda in North Africa Darniah), and Al Qaeda in Pakistan (Tehrik i Taliban), aka US federal government?

My Mac is version 10.6. The command tool lines are not available for my mac. How can I use the terminal to compile c grogram? Thanks in advance.

I have been visiting this site for a quite a while. The information found here are very useful and pretty neat. I did not care to add any comments. But I just want to say that this is very wonderful and I believe you will continue this work.

thanks a lot for explaining the steps clearly. im using the mac for the first time and installed it without any trouble.

Ahh you are great my friend, thank you. I’ve spent one week for doing this. Thank you. Regards from Puebla, Mexico.

Mac OSX should bundle gcc compiler.

i have already download the the xcode thing. But i don’t know how to reach to step 4 and do i key in “gcc function.php” or “gcc -v” into the blank in order to download the gcc compiler into macbook?

In step3, gcc compiler is installed along with the xcode. Step 4 is for verification, run “terminal” (launchpad -> other) and “gcc -v” to test the installed version.

Thank you, I can now compile C/C++ programs in Netbeans 7.2. was looking for it.

Hello, I could use a little assistance. I’ve installed the compiler as instructed. I’ve by this point created a source code using Bluefish text editor, following all instructions I was given. The book I’m learning from tells me to “compile the source code” for the file i’ve created (named DUMB.C). it tells me that the command to do so with “most compilers” is gcc dumb.c -o dumb I do this, and though I do not receive an error message… nothing happens. Nothing at all. And my instructions tell me that a message is supposed to be displayed on the screen. … Read more »

. Then you will see the message.

AHHH oh my God I figured it out! I’ve been struggling in frustration with this for 36 hours, and I figured it out on my own! I’m not supposed to see the message by simply compiling. I then have to RUN the program. If only that part was BOLDED in my instruction booklet—> what a relief!

sorry to have bothered- thank you though!

Thanks. Everything works рџ™‚

[…] How to install gcc compiler on Mac OS X […]

Hi! I tried compiling and running my codes in terminal. But this errors appears: Undefined symbols: “std::basic_ostream & std::operator (std::basic_ostream &, char const*)”, referenced from: _main in ccvKjPUB.o “std::ios_base::Init::Init()”, referenced from: __static_initialization_and_destruction_0(int, int)in ccvKjPUB.o “std::basic_string ::size() const”, referenced from: std::__verify_grouping(char const*, unsigned long, std::basic_string const&)in ccvKjPUB.o “std::basic_string ::operator[](unsigned long) const”, referenced from: std::__verify_grouping(char const*, unsigned long, std::basic_string const&)in ccvKjPUB.o std::__verify_grouping(char const*, unsigned long, std::basic_string const&)in ccvKjPUB.o std::__verify_grouping(char const*, unsigned long, std::basic_string const&)in ccvKjPUB.o “___gxx_personality_v0”, referenced from: std::__verify_grouping(char const*, unsigned long, std::basic_string … Read more »

Thank you mkyong, you are a very good man!

[…] working in your machine install the Command Line Tools for Xcode (how to do so you can find here). Once you have it installed type the command below to check out if it […]
Читайте также:  Установка границ земельного участка по кадастровому номеру


Install GNU GCC on mac

I have recently become frustrated with the new clang compiler included with Xcode 5. I was wondering what the best way to install GNU GCC on OS X would be.

  • I don’t want to use MacPorts, fink, homebrew or any other third party package manager.
  • I would like to use the latest GCC, compiled from source, if possible.
  • I need the existing GCC (hardlink to clang) to remain the default, but to easily be able to use GNU GCC when I need to.
  • I would like to avoid modifying the code if at all possible.

EDIT: Success! Using GCC 4.9.2 (with GMP 5.1.3, MPFR 3.1.2, MPC 1.0.2, ISL 0.12.2, and CLooG 0.18.1) I succesfully built GCC. Tips to take from here:

  • Make sure you use ISL and CLooG. Yes, they are optional, but they make a more optimised compiler and I had trouble building without them. Make sure you use ISL 0.12, not the latest version (0.14).
  • If possible, use the standalone Developer Tools, not XCode. (XCode has some buggy headers, and while I didn’t notice any issues building GCC I have had issues with other software (e.g. GPG)).
  • I recommend putting all your sources in the gcc directory, rather than building and installing separately (it’s faster this way)
  • Make sure you invoke configure with CC=clang CXX=clang++ so GCC knows it isn’t being compiled by GCC.
  • Definitely, definitely, definitely, invoke make with -j8 , or otherwise the build will take about 4 hours! (With -j8 , it took 1 1/3 hours on my Mid-2012 MBP with 8gb RAM.) ( make -j8 means make can build 8 threads simultaneously (4 cores + HT), whereas on a 2-core machine you would run make -j4 .)

3 Answers 3

Download the source for GCC and numerous supporting packages. The instructions are in the gcc-4.x.y/INSTALL/index.html file in the GCC source code, or online at http://gcc.gnu.org/install/.

Use a script to extract the source for GCC and the support libraries into a directory, create the object directory, and run the build.

This is the script I used for GCC 4.8.2:

When that finishes, run the install too. Then add $HOME/gcc/gcc-4.8.2/bin (the name you specify in —prefix plus /bin ) to your PATH ahead of /usr/bin .

With a decent MacBook Pro with a 5400 rpm spinning disk, it takes an hour or two to compile everything (using the -j8 option to make ), and requires multiple gigabytes of disk space while compiling. SSD is nice when doing this (definitely faster)!

GCC 4.9.0 was released on 2014-04-22. I’ve installed it using basically the same process, but with CLooG 0.18.1 and ISL 0.12.2 (required updates) and GMP 5.1.3 (and 6.0.0a), MPC 1.0.2 (or 1.0.1) and MPFR 3.1.2 on Mac OS X 10.9.2 Mavericks and an Ubuntu 12.04 derivative. Beware that the gmp-6.0.0a.tar.xz extracts into directory gmp-6.0.0 (not gmp-6.0.0a as you might expect).

Between 2014 and 2017-09-27, I’ve built GCC versions 4.9.0, 4.9.1, 5.1.0, 5.2.0, 5.3.0, 6.1.0, 6.2.0, 6.3.0, 7.1.0 with only minor variations in the build script shown below for GCC 7.2.0 on macOS Sierra (10.12). The versions of the auxilliary libraries changed reasonably often.

macOS Sierra and High Sierra

On 2017-08-14, I used a minor variant of the script above to build GCC 7.2.0 on macOS Sierra 10.12 (using XCode 8 as the bootstrap compiler). One change is that CLooG doesn’t seem to be needed any more (I stopped adding it with GCC 6.2.0). This is my current script:

Make sure your version of tar supports all 4 different compressed file formats ( .lz , .gz , .xz , .bz2 ), but since the standard Mac version of tar does that for me, it’ll probably work for you too.

On 2017-09-27, I failed to build GCC 7.2.0 on macOS High Sierra 10.13 (using XCode 9 for the bootstrap compiler) using the same script as worked on Sierra 10.12. The immediate error was a missing header ; I’ll need to track down whether my XCode 9 installation is correct — or, more accurately, why it isn’t correct since is a standard header in C++98 onwards. There’s probably an easy fix; I just haven’t spent the time chasing it yet. (Yes, I’ve run xcode-select —install multiple times; the fact that I had to run it multiple times because of network glitches may be part of the trouble.) (I got GCC 7.2.0 to compile successfully on 2017-12-02; I don’t recall what gymnastics — if any — were required to get this to work.)

Time passes; version numbers increase. However, the basic recipe has worked for me with more recent versions of GCC. I have 7.3.0 (installed 2018-01-2), 8.1.0 (installed 2018-05-02), 8.2.0 (installed 2018-07-26), 8.3.0 (installed 2019-03-01) and now 9.1.0 (installed today, 2019-05-03). Each of these versions was built and installed on the current version of macOS at the time, using the current version of XCode for the bootstrap phase (so using macOS 10.14.4 Mojave and XCode 10.2.1 when building GCC 9.1.0)


nix Craft

Linux and Unix tutorials for new and seasoned sysadmin

nix Craft

Linux and Unix tutorials for new and seasoned sysadmin

Mac OS X: Install GCC Compiler with Xcode

Adblock detected 😱

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.
Fig.01: Make sure Xcode developer tools are install OS X

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:

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 app 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 int main(void)

To compile, enter:
$ make a
Run it as follows:
$ ./a
Sample outputs:
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:

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Related Tutorials

Your support makes a big difference:

I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft takes a lot of my time and hard work to produce. If everyone who reads nixCraft, who likes it, helps fund it, my future would be more secure. You can donate as little as $1 to support nixCraft:

28 comment

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:

asaffeldman$ $gcc –version
-bash: –version: command not found

with 2 dashes and no $ in front of it
hope it helps!

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

when I typed make a I got this message:
make: *** No rule to make target `a’. Stop.

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 don’t have the Command Line option in my preference. Help!


joegoggins / install and add gcc arm to PATH.sh

# Download the file manually from here https://launchpad.net/gcc-arm-embedded
# Note: `curl` command doesn’t work
# I downloaded this one: «gcc-arm-none-eabi-4_7-2013q3-20130916-mac.tar.bz2»
# double click it to unzip it
# Make a place to install it to
mkdir /usr/local/gcc_arm
# Move the unzipped stuff there.

/Downloads/gcc-arm-none-eabi-4_7-2013q3 /usr/local/gcc_arm/ # Check out all the purdy binaries, you’ll need to build firmware. ls /usr/local/gcc_arm/gcc-arm-none-eabi-4_7-2013q3/bin/ # arm-none-eabi-addr2line arm-none-eabi-gcc-4.7.4 arm-none-eabi-ld.bfd # . # arm-none-eabi-gcc . # Peep your current PATH echo $PATH # /usr/local/heroku/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin: # Change your PATH by appending the «bin» folder of the folder # NOTE: You should also add this line to

/.bash_profile (in your home directory) # so you don’t have to remember to do this every time you want to compile firmware. export PATH= » $PATH :/usr/local/gcc_arm/gcc-arm-none-eabi-4_7-2013q3/bin/ « # Check to ensure the gcc-arm firmware compiler is available (so `make clean dependents all` will work.) arm-none-eabi-gcc —version # arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.7.4 20130913 (release) [ARM/embedded-4_7-branch revision 202601]

This comment has been minimized.

blakejakopovic commented May 31, 2014

Avoid using The Unarchiver.app mac app to extract the tar.bz2 archive. It messes up the symlinks, and things wont work. Instead, use the Archive Utility.app built into OS X (by right clicking the archive and selecting from open with ). (Tested using OS X 10.9.3, The Unarchiver 3.9.1)

This comment has been minimized.

ericboehs commented Jun 23, 2014

I went a bit crazy with the script. Uploaded the bzip2 to S3 for speed (launchpad was very slow), made it idempotent, and made it installable via a one liner:

Next step, homebrew formula.

This comment has been minimized.

ericboehs commented Jun 23, 2014

All that work and there’s already a homebrew formula. Should have googled harder:

This comment has been minimized.

machadolab commented Jul 5, 2014

Well, thanks for the efforts and pointing out there is already a formula! Saved me some time. 🙂

This comment has been minimized.

shoaibuddin commented Jul 15, 2014

@ericboehs Awesome! Save so much time.

This comment has been minimized.

peterschwarz commented Jul 18, 2014

Unfortunately, the homebrew formula doesn’t seem to correctly setup the includes necessary to build the core-firmware.

This comment has been minimized.

AndoniV commented Jul 28, 2014

This comment has been minimized.

metcalf commented Aug 12, 2014

The latest firmware requires GCC 4.8:

brew install gcc-arm-none-eabi-48

(this fixes the «stdatomic.h: No such file or directory» error.)

This comment has been minimized.

ericboehs commented Aug 19, 2014

The latest firmware requires GCC 4.8

This took me far too long to find the solution. So for some Google juice, this solves these errors:

You’ll also want to uninstall the older version first:

And throw in a make clean all for good luck. And make sure you have the latest, unmodified versions of the 3 git repos.

This comment has been minimized.

technobly commented Aug 25, 2014

I tried the homebrew route on a fresh machine. worked perfectly! Thanks all!

Step 2 — Install GCC Arm Toolchain

This comment has been minimized.

noob1211 commented Jun 9, 2015

48 no longer works try 49

This comment has been minimized.

m-mcgowan commented Aug 26, 2015

no longer works- formula not found. but

This comment has been minimized.

adeeshag commented Oct 28, 2015

brew install gcc-arm-none-eabi-49 works now. 48 doesn’t work anymore

This comment has been minimized.

jeremyheiler commented Apr 25, 2016

This comment has been minimized.

Anderson69s commented May 31, 2016

Is it still working on OSX 10.11?

This comment has been minimized.

wamburu commented Feb 24, 2017

This comment has been minimized.

simonwo commented Feb 26, 2017

@jeremyhelier This is what I needed, thanks!

This comment has been minimized.

tehong commented Mar 16, 2017 •

@jeremyhelier Thanks. You’re solution is the simplest.

This comment has been minimized.

chris-zen commented Apr 9, 2017 •

@jeremyheiler, is there something similar in brew for arm-unknown-linux-gnueabihf ?

This comment has been minimized.

josepedrodiaz commented Aug 19, 2017

This comment has been minimized.

av-ivashchenko-sigma commented Sep 29, 2017

This comment has been minimized.

JoseFreak95 commented Nov 17, 2017

Thank u dude!. It’s save me lot of time

This comment has been minimized.

sandyr7 commented Nov 20, 2017

This comment has been minimized.

FrozenDro >Nov 22, 2017

Pretty cool, however I ended up just using brew install caskroom/cask/gcc-arm-embedded , which is working well for me.

This comment has been minimized.

saogalde commented Nov 26, 2017

This comment has been minimized.

JayKickliter commented Dec 26, 2017

@chris-zen There’s no easy solution from the best that I can tell. I’ve tried building that toolchain using crosstool-ng and have not had success yet.

This comment has been minimized.

davewhiiite commented Jan 6, 2018

This worked exactly as you described. Thank you!

This comment has been minimized.

lukaszmargielewski commented Jan 17, 2018

Maybe I am missing something but why not just download pre-build and validated toolchain from the ARM dev portal?:

This comment has been minimized.

tntclaus commented Mar 25, 2018

@lukaszmargielewski that’s exactly what brew install caskroom/cask/gcc-arm-embedded does 🙂

This comment has been minimized.

impressivemachines commented Apr 24, 2018 •

The last two comments were pretty useful. I could understand downloading the binaries and putting them in the /usr/local directory and setting your PATH, however I had no idea what home-brew would do to install things, where it would put them, or whether the version it would install will be the same one.

So while I did download (but did not install) «gcc-arm-none-eabi-7-2017-q4-major-mac.tar.bz2», I decided to try the «brew install caskroom/cask/gcc-arm-embedded» first.

This worked. The cask room formula is here https://github.com/caskroom/homebrew-cask/blob/master/Casks/gcc-arm-embedded.rb, which is pretty readable, and it just downloaded the same file as I initially downloaded manually:

==> brew cask install caskroom/cask/gcc-arm-embedded
==> Satisfying dependencies
==> Downloading https://developer.arm.com/-/media/Files/downloads/gnu-rm/7-2017q4/gcc-arm-none-eabi-7-2017-q4-major-mac.tar.bz2
######################################################################## 100.0%
==> Verifying checksum for Cask gcc-arm-embedded
==> Installing Cask gcc-arm-embedded
==> Linking Binary ‘arm-none-eabi-strip’ to ‘/usr/local/bin/arm-none-eabi-strip’.
==> Linking Binary ‘arm-none-eabi-ar’ to ‘/usr/local/bin/arm-none-eabi-ar’.
==> Linking Binary ‘arm-none-eabi-as’ to ‘/usr/local/bin/arm-none-eabi-as’.
==> Linking Binary ‘arm-none-eabi-c++’ to ‘/usr/local/bin/arm-none-eabi-c++’.
==> Linking Binary ‘arm-none-eabi-c++filt’ to ‘/usr/local/bin/arm-none-eabi-c++filt’.
==> Linking Binary ‘arm-none-eabi-cpp’ to ‘/usr/local/bin/arm-none-eabi-cpp’.
==> Linking Binary ‘arm-none-eabi-elfedit’ to ‘/usr/local/bin/arm-none-eabi-elfedit’.
==> Linking Binary ‘arm-none-eabi-g++’ to ‘/usr/local/bin/arm-none-eabi-g++’.
==> Linking Binary ‘arm-none-eabi-gcc’ to ‘/usr/local/bin/arm-none-eabi-gcc’.
==> Linking Binary ‘arm-none-eabi-gcc-ar’ to ‘/usr/local/bin/arm-none-eabi-gcc-ar’.
==> Linking Binary ‘arm-none-eabi-gcc-nm’ to ‘/usr/local/bin/arm-none-eabi-gcc-nm’.
==> Linking Binary ‘arm-none-eabi-gcc-ranlib’ to ‘/usr/local/bin/arm-none-eabi-gcc-ranlib’.
==> Linking Binary ‘arm-none-eabi-gcov’ to ‘/usr/local/bin/arm-none-eabi-gcov’.
==> Linking Binary ‘arm-none-eabi-gcov-tool’ to ‘/usr/local/bin/arm-none-eabi-gcov-tool’.
==> Linking Binary ‘arm-none-eabi-gdb’ to ‘/usr/local/bin/arm-none-eabi-gdb’.
==> Linking Binary ‘arm-none-eabi-gdb-py’ to ‘/usr/local/bin/arm-none-eabi-gdb-py’.
==> Linking Binary ‘arm-none-eabi-gprof’ to ‘/usr/local/bin/arm-none-eabi-gprof’.
==> Linking Binary ‘arm-none-eabi-ld’ to ‘/usr/local/bin/arm-none-eabi-ld’.
==> Linking Binary ‘arm-none-eabi-ld.bfd’ to ‘/usr/local/bin/arm-none-eabi-ld.bfd’.
==> Linking Binary ‘arm-none-eabi-nm’ to ‘/usr/local/bin/arm-none-eabi-nm’.
==> Linking Binary ‘arm-none-eabi-objcopy’ to ‘/usr/local/bin/arm-none-eabi-objcopy’.
==> Linking Binary ‘arm-none-eabi-objdump’ to ‘/usr/local/bin/arm-none-eabi-objdump’.
==> Linking Binary ‘arm-none-eabi-ranlib’ to ‘/usr/local/bin/arm-none-eabi-ranlib’.
==> Linking Binary ‘arm-none-eabi-readelf’ to ‘/usr/local/bin/arm-none-eabi-readelf’.
==> Linking Binary ‘arm-none-eabi-size’ to ‘/usr/local/bin/arm-none-eabi-size’.
==> Linking Binary ‘arm-none-eabi-strings’ to ‘/usr/local/bin/arm-none-eabi-strings’.
==> Linking Binary ‘arm-none-eabi-addr2line’ to ‘/usr/local/bin/arm-none-eabi-addr2line’.
gcc-arm-embedded was successfully installed!

So I learned something about home-brew as well as got an easy install.

After this install, all the documentation is under:
For example:

Example code and example startup assembler files for M0, M3, M4, M7 are under

The next thing you’re going to need to do however is download and install CMSIS, the ARM CPU common headers and run time libraries.

Lastly you’re going to need the header files for the peripherals from the manufacturer of your specific ARM part.


Добавить комментарий