I'd like to install gcc version 9.3.0 on my Mac Os Big Sur. I was wondering if I can do this still using brew?
I already have the most up to date version of brew but I would like to possibly downgrade or have in addition gcc v9.3.0.
I followed the three commands below
brew tap-new $USER/local-gcc
brew extract --version=9.3.0 gcc $USER/local-gcc
brew install gcc#9.3.0
but when I do
brew info gcc
it still says I have v10.2.0. Is there a way to switch between different versions? As far as I can tell brew switch is now broken.
If there is another way to get a working gcc v 9.3.0 that you can recommend I am happy to try it too. Thanks in advance.
EDIT:
I have the most up to date version of gcc on my Mac OS Big Sur machine via brew install gcc but now I would like to have gcc#9 in addition or in place of it. I have gcc#9in /usr/local/Cellar/gcc#9/9.3.0_1 but I can't find a way for my system to use this rather than gcc10. When I do brew ls --versions gcc, it still returns gcc 10.2.0_4.
Related
I've installed gcc-4.6 using the homebrew-alternatives gcc formula, but I can't seem to get it to use that GCC to install other formulas. Specifically Open-MPI and boost.
Does anyone know how to make Homebrew use this new compiler?
Thanks!
It looks like the latest versions of Homebrew now support the HOMEBREW_CC and HOMEBREW_CXX environment variables.
So now you can do the following:
$ HOMEBREW_CC=gcc-4.2 HOMEBREW_CXX=g++-4.2 brew install ice
Homebrew can't adapt to other versions of gcc using command line options. You can easily override the older compiler, though, if you edit the open-mpi and boost formula. For example, you can add a few commands after the "def install" in open-mpi.rb:
def install
# Force compilation with gcc-4.6
ENV['CC'] = '/usr/local/bin/gcc-4.6'
ENV['LD'] = '/usr/local/bin/gcc-4.6'
ENV['CXX'] = '/usr/local/bin/g++-4.6'
# Compiler complains about link compatibility with FORTRAN otherwise
ENV.delete('CFLAGS')
ENV.delete('CXXFLAGS')
That worked for me on Lion. Good luck.
These answers are all fairly old now. It seems that recent versions of homebrew have a '--cc' option that enables you to select the c compiler to use. For example
brew install --cc=gcc-6 <package-name>
will install using the brew version of gcc
From their wiki it sounds like they don't support other compilers:
Installing a custom version of GCC or autotools into the $PATH has the potential to break lots of compiles. So we stick to the Apple-provided compilers.
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, your brew command should have installed gcc-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 by homebrew with the full path like this:
/usr/local/bin/gcc-4.9 --version
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
export PATH=/usr/local/bin:$PATH
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 typing
gcc-4.9 --version
Option 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 this
cd /usr/local/bin
ln -s gcc-4.9 gcc
That will allow you to run the homebrew-installed gcc by simply typing gcc at the command line, like this
gcc --version
Note:
If you later want to install, say gcc-4.13 or somesuch, you would do your brew install as before, then change the symbolic link like this:
cd /usr/local/bin
rm gcc # remove old link from gcc to gcc-4.9
ln -s gcc-4.13 gcc # make new link from gcc to gcc-4.13
Note that if you are actually using C++ rather than C, you will need to adapt the above for g++ in place of gcc.
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 me
changing the alias in your ~./bash_profile (alias gcc='gcc-5') works, but can be confusing i.e. which gcc will return the Clang version
what worked for me was to make a symbolic link in the brew gcc directory as well as update the path (point 1 above)
cd /usr/local/Cellar/gcc/5.1.0/bin/gcc
ln -s gcc-5 gcc
now which gcc returns the correct version 5.1.0
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.
I had OpenMP compiling and executing in C/C++ on my Mac but then I formatted and reinstalled a fresh copy of OS X. I believe the only difference in the setup was that I had Xcode 5 before the format, and now I have Xcode 6.
Now I get fatal error: 'omp.h' file not found
I read this has something to do with clang and gcc, but, my confusion lies with why did it work before and now its not working?
After some research I seem to have found an answer.
GCC included in the latest version of Xcode (Xcode 6) is only a symbolic link to clang. Since clang does not support OpenMP at this time, you need to install a different version of GCC. The easiest way to do this would be to use Homebrew or MacPorts.
Keep in mind that even when you do this you will probably need to alter your $PATH to have /usr/local come before /usr/bin. This is because Homebrew will have placed your newly installed GCC in /usr/local. Also, some implementations may name the command gcc-49 instead of plain gcc.
Mac OSX uses clang.The gcc compiler in OS X does not support OpenMP. To use this feature a new gcc compiler needs to be installed.
Go to Terminal, if you have not installed Hombrew, install it:
/usr/bin/ruby -e "$(curl -fsSL https://`enter code here`raw.githubusercontent.com/Homebrew/install/master/install)"
then install new version of gcc
brew reinstall gcc --without-multilib
This will not make changes to the existing gcc compiler installed by Xcode as we are reinstalling it.
After running the command given below compile the files using the new version of gcc using the syntax : gcc-version -fopenmp filename.c
To find the version type gcc and then press tab. This will list out all the possible variants of gcc. The version number can be found out from this. For example : gcc-6, gcc-4.9,etc
I'd like to build the latest version of gcc on a mac. I have the latest xcode but I'm looking for some of the c++0x features that are in more recent versions (the lambda functions, etc).
Are there any good step-by-step tutorials on doing this?
You should look at the Homebrew project.
Homebrew allows you to do things like this:
brew install gcc
Mac homebrew installation instructions are available here.
Add GCC support to a fresh Xcode 4.2 installation using this homebrew formula:
brew install https://raw.github.com/Homebrew/homebrew-dupes/master/apple-gcc42.rb
Upgrading from Xcode 4.1 doesn't drop existing GCC support, so this formula is only useful if you're working with a fresh 4.2+ installation.
One option is to install MacPorts and install the gcc46 package:
sudo port install gcc46
Another option is to download the source code and build it as follows:
tar xzvf gcc-4.6.0.tar.gz
cd gcc-4.6.0
./configure
make
Note that GCC 4.6.0 requires as prerequisites GMP 4.2+, MPFR 2.3.1+, and MPC 0.8.0+. If ./configure fails, it's probably because you're missing one of these (though it should give you a helpful error message in any case).
Building will take a while—likely several hours, depending on your hardware.
I would suggest building it yourself (Adam details how to do so). This will give you fine control on where to install and all the options you want to select. My experience from having multiple versions of gcc is that, if care is not taken apple's version of gcc can be damaged.
To speed up gcc installation you might want to look at --enable-languages option. If there are languages you don't need installed with the new gcc then you may not want to select them.
We have a new application that requires glibc 2.4 (from gcc 4.1). The machine we have runs on has gcc 3.4.6. We can not upgrade, and the application must be run on this machine.
We installed gcc 4.1, however, when it comes to compile time it is using all the includes, etc, from 3.4.6.
How do we get around this?
Any suggestions on using 4.1 for just this application?
Refer "How to install multiple versions of GCC" here in the GNU GCC FAQ.
There's also a white paper here.
for Ubuntu it's pretty easy
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
and then install for example gcc version 6
sudo apt-get install gcc-6
Have you tried gcc-select? Otherwise, try setting the INCLUDE_PATH and LIBRARY_PATH in your shell.
update-alternatives is a very good way to have multiple gcc versions:
http://ubuntuguide.net/how-to-install-and-setup-gcc-4-1g4-1-in-ubuntu-10-0410-10
You possibly still execute the old gcc. Try making a symlink from gcc to your version of it, like
ln -s gcc-4.1 gcc
Beware of not removing an old "gcc" binary placed there, in case they placed not just a symlink. If you can recompile your own gcc version, the safest is just use another prefix at configure time of gcc, something like --prefix=/home/jojo/usr/gcc (i did it that way with gcc-4.4 from svn-trunk, and it worked great).
Note that that just runs the right gcc version. If you update your gcc, your glibc won't be updated automatically too. It's a separate package which is deeply coupled with the rest of the system. Be careful when installing another glibc version.