1

This is really annoying. For some reason, on MacOS X 10.11 (probably also on previous versions) there are gcc and g++ commands (in /usr/bin, they are not aliases or so) which, when executed with the -v argument, give:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.2.0
Thread model: posix

So it looks like they actually execute the clang and clang++ compilers by apple. Now, I really need my computer to execute gcc and g++ when I invoke those commands, both from the terminal and through makefiles.

The reasons for this are two:

  1. I like to have my computer do what I ask it to do.
  2. Apparently clang++ compiles stuff using a different c++ standard library from g++, and this is causing me problems when I compile and link my stuff with g++-5 (the ACTUAL g++, installed via homebrew) against CppUnit.

Does anybody know what is the best way to have gcc and g++ actually call gcc and g++?

Lorenzo Stella
  • 242
  • 2
  • 11

2 Answers2

4

Include in your PATH, before /usr/bin, a directory that contains a symbolic link named gcc pointing to /…/bin/gcc-5.

The latest Mac OS X does not let you change /usr, from what I hear, so this conservative solution is the only one available.

when I invoke those commands, both from the terminal and through makefiles.

If you adjust your PATH variable in your .profile, both these cases will be covered.

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
  • `/opt/local/bin` sounds like MacPorts, which OP may not have installed/used. – Thomas Dickey Dec 25 '15 at 22:21
  • @ThomasDickey Ah, yes, I thought the OP had mentioned MacPorts in the question but it was actually homebrew. – Pascal Cuoq Dec 25 '15 at 22:44
  • yes (I'll stick with MacPorts, since *I* use `/usr/local`). By the way, only parts of `/usr` are "protected" (it seems they made a special exception for `/usr/local`). I noticed this because they quarantined my build-tree (would be nice if they'd thought it through, and made the feature configurable). – Thomas Dickey Dec 25 '15 at 22:48
1

Apple does not actually provide gcc or g++, although (perhaps only misguided) they make aliases to pretend that clang is the same.

You can install gcc and g++ with MacPorts (also with homebrew). I use MacPorts, which puts its executables in /opt/local/bin.

With MacPorts, I see these currently-available ports (programs that have to be compiled to work on one's machine), using this command

port list |grep gcc

gcc410                         @5-20140817     lang/gcc410 
gcc43                          @4.3.6          lang/gcc43 
gcc44                          @4.4.7          lang/gcc44 
gcc45                          @4.5.4          lang/gcc45 
gcc46                          @4.6.4          lang/gcc46 
gcc47                          @4.7.4          lang/gcc47 
gcc48                          @4.8.5          lang/gcc48 
gcc49                          @4.9.3          lang/gcc49
gcc5                           @5.2.0          lang/gcc5
gcc6                           @6-20151129     lang/gcc6
gccxml-devel                   @20150423       lang/gccxml-devel
gcc_select                     @0.1            sysutils/gcc_select
gccmakedep                     @1.0.3          x11/gccmakedep

According to its webpage, brew would do something similar, but install into /usr/local/bin.

When I installed MacPorts, its installer updated my ~/.profile, adding this to update PATH:

# MacPorts Installer addition on 2015-10-03_at_14:17:30: adding an appropriate PATH variable for use with MacPorts.
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
# Finished adapting your PATH environment variable for use with MacPorts.

Each of those ports from MacPorts installs gcc with a different name, and the port script has a feature select which establishes a symbolic link, e.g., from gcc to gcc49. brew has something similar. According to How can I brew link a specific version?, you would use

brew switch gcc-package-name package-version

e.g., (guessing at a valid name)

brew switch gcc 4.9
Community
  • 1
  • 1
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • The OP says they already installed gcc through homebrew. Neither installing through homebrew nor installing through MacPorts alone makes `gcc` actually call GCC, which is the OP's question, because it is installed with a name like `gcc-mp-5` or `gcc-5`. – Pascal Cuoq Dec 25 '15 at 22:50