This has been plaguing me for awhile now. I am trying to compile a huge C++ file (I know it works as I it works fine on my Arch Linux computer at work). When I checked my GCC version on my mac It returns the following
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
I have also installed the most recent GCC version using Homebrew with
brew install gcc49
My question now is how do I apply that newly installed GCC version to be the default version that the terminal uses?
I am also aware that when you use homebrew to isntall gcc it names it gcc-49 so that there is no confusion between packages.
I have no idea how to replace the 4.2.1 version that comes with XCode with the 4.9 version I have installed.
Thanks
Edit: Switched to my mac to get the full return statement of gcc --version
Edit 2: My end game here is to be able to navigate to the directory and be able to type
make
sudo make install
to install the daemon that has been made. Right now that returns tons of errors with random packages and the Standard Library
By default,
homebrew
places the executables (binaries) for the packages it installs into/usr/local/bin
- which is a pretty sensible place for binaries installed by local users when you think about it - compared to/bin
which houses standardisded binaries belonging to the core OS. So, yourbrew
command should have installedgcc-4.9
into/usr/local/bin
. The question is now how to use it... you have several options.Option 1
If you just want to compile one or two things today and tomorrow, and then probably not use the compiler again, you may as well just invoke the
gcc
installed byhomebrew
with the full path like this:Option 2
If you are going to be using
gcc
quite a lot, it gets a bit tiresome explicitly typing the full path every time, so you could put the following into your~/.bash_profile
and then start a new Terminal and it will know it needs to look in
/usr/local/bin
, so you will be able to get away with simply typingOption 3
If you just want to use
gcc
to invoke the compiler, without worrying about the actual version, you can do Option 2 above and additionally create a symbolic link like thisThat will allow you to run the
homebrew
-installedgcc
by simply typinggcc
at the command line, like thisNote:
If you later want to install, say
gcc-4.13
or somesuch, you would do yourbrew install
as before, then change the symbolic link like this:OS X does not come with GCC installed (4.2.1 or otherwise). Clang is the default system compiler and has been for some time. It is using the C++ headers from 4.2.1 when invoked as GCC. Have you tried compiling your code with Clang natively, instead of calling "gcc" (which calls Clang)? It has more modern headers and C++ support than the GCC emulation mode.
Download the gcc binaries untar and copy the bin, lib include share and libexec files to your /usr directory then type gcc --version this is what i expect you to see
gcc --version gcc (GCC) 4.9.2 20141029 (prerelease) Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
simply updating the order of $PATH in ~/.bash_profile to the brew installed version
'export PATH=/usr/local/Cellar/gcc/5.1.0/bin:$PATH'
was not enough to make the switch for mechanging the alias in your ~./bash_profile (
alias gcc='gcc-5'
) works, but can be confusing i.e.which gcc
will return the Clang versionwhat worked for me was to make a symbolic link in the brew gcc directory as well as update the path (point 1 above)
now
which gcc
returns the correct version 5.1.0