2

I have installed Xcode and the command line tools from the Mac Developers website, which I have read a few times is a prerequisite. I also installed the MacPorts program. In terminal:

sudo port install gcc48
sudo port select -set gcc mp-gcc48

All the above went smoothly until I type:

hash gcc

When I press enter, I get the following error message:

-bash: hash: gcc: not found

I am at a loss and do not know how to proceed to successfully install gcc on my Mac (which is running Mac OS X 10.9.1).

Much obliged to any suggestions and or alternatives to installing the gcc

  • 3
    Any reason you need gcc specifically? clang uses the same syntax, compiles faster, and generates faster code. The major bugs have been squashed in the past few years. – Kevin Chen Jan 27 '14 at 6:06
  • An edit would help this. If you have a package you need to compile, list that. If you just want to know how to make gcc compile for the fun of it, that's fine too but the answer to either is different. – bmike Jan 27 '14 at 6:09
  • What does which gcc give? – user151019 Mar 3 '14 at 23:54
  • Did you check your path variable in your ~/.profile? It should point to the directory in which gcc is located. – Peter Kämpf Jun 15 '14 at 18:57
  • What does ;s -l /opt/local/bin/gcc* show? – user151019 Jun 15 '14 at 19:07
6

You might be better off installing gcc from homebrew than Macports.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew doctor
brew update
brew search gcc

There're are about 6 versions of gcc available from this package manager. See http://brew.sh for more details on the homebrew tools. Also this thread has more details on gcc and homebrew: How do I install GCC via Homebrew? Lastly, the gcc error in your shell is similar to this thread: I installed Xcode but I still don't have gcc in my terminal

  • 3
    Why would this be better than macports? – user151019 Mar 3 '14 at 23:52
1

Their might be two problems. One problem is your path. You need to have /opt/local/bin in front of /usr/bin currently you have /opt/local/bin behind /usr/bin. Because of this g++ is probably still linking to clang.

The other problem is you are using the port select command wrong. The port select command automatically makes a g++ flag link to your specified compiler. In this case the specified compiler should be mp-4.8 and should be --set instead of -set. The directions are on this webpage http://dropbit.com/?p=84.

-1

I don't think your port select command did what you expected. The manual states that the select command selects between multiple versions of a versioned port, which I believe is not your case here:

pejvan$ port help select
Usage: select --list --set --show --summary <arguments>

Select between multiple versions of a versioned port

This allows you to choose which version, among several installed versions
of a port, is to be considered primary.  What this means is which version
becomes the one most would consider the default, e.g. the one run without
specifying any version.

After you successfully run the install command for gcc (here version 4.9):

sudo port install gcc49

You can verify you've got the gcc binaries installed:

pejvan$ ls -l /opt/local/bin/gcc*
-rwxr-xr-x  2 root  admin    42912  3 Jun 03:44 /opt/local/bin/gcc-ar-mp-4.9
-rwxr-xr-x  3 root  admin  1082788  3 Jun 03:44 /opt/local/bin/gcc-mp-4.9
-rwxr-xr-x  2 root  admin    42992  3 Jun 03:44 /opt/local/bin/gcc-nm-mp-4.9
-rwxr-xr-x  2 root  admin    43000  3 Jun 03:44 /opt/local/bin/gcc-ranlib-mp-4.9

You can then run gcc with the full path to the binaries:

pejvan$ gcc-mp-4.9 --version
gcc-mp-4.9 (MacPorts gcc49 4.9-20140416_2) 4.9.0 20140416 (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.

If you want to replace (temporarily or permanently) the clang complier by gcc, you can do it by setting the CC env var the following way for example:

export CC=/opt/local/bin/gcc-mp-4.9 # set GCC as default C compiler

As a side note, please note that for the port select gccVersion to work, you will need to install gcc_select:

pejvan$ port info gcc_select
gcc_select @0.1_8 (sysutils)

Description:          gcc_select installs files that allow 'port select' to switch the default version of gcc. It symlinks the standard compiler executables in
                      the MacPorts prefix to the selected version.

I haven't looked at the details of the package, so I'm not sure whether it would work between clang and port installed gcc or only with several different versions of port installed gcc packages.

  • Only between gcc packages and port select should have worked – user151019 Jun 15 '14 at 19:06
  • That's what I stated in first sentence, mate. – Pejvan Jun 15 '14 at 19:49
  • 1
    (BUT you need to install the gcc_select package, which does not appear to be the case here). – Pejvan Jun 15 '14 at 19:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .