13

I am working on OS X 10.7 (Lion). I have installed gcc 4.7 from macports:

sudo port install gcc47

It seems to be working properly:

$ /opt/local/bin/gcc-mp-4.7 -v
(...)
gcc version 4.7.0 (GCC) 

Now, I am trying to change default compiler by using port select:

$ sudo port select gcc mp-gcc47
Selecting 'mp-gcc47' for 'gcc' succeeded. 'mp-gcc47' is now active.

It copies gcc binary to /opt/local/bin/gcc, which works properly:

$ /opt/local/bin/gcc -v
(...)
gcc version 4.7.0 (GCC) 

It also changes default gcc:

$ which gcc
/opt/local/bin/gcc

But running this default one does not work:

$ gcc -v
gcc-mp-4.7: error trying to exec '/opt/local/bin/i686-apple-darwin11-llvm-gcc-4.2': execvp: No such file or directory

This binary "i686-apple-darwin11-llvm-gcc-4.2" is the original Apple's provided gcc version; I don't know why it tries to look on it in /opt/local/bin, or even why it tries to run it at all. If I create symlink, it simply calls this binary, which is not what I want:

$ sudo ln -s /usr/bin/i686-apple-darwin11-llvm-gcc-4.2 /opt/local/bin
$ gcc -v
(...)
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)

How to solve it, to make gcc working properly, by simply calling "gcc"? As far as I know, there was gcc_select tool in older OS X, but my system does not have it.

2 Answers 2

17

Most likely it is because bash has gcc hashed.

Run

$ hash

to see which commands are hashed. If /usr/bin/gcc appears on the list, run

$ hash gcc

to rehash gcc. Afterwards you should see /opt/local/bin/gcc if you run hash, and running gcc should run the macports version – providing of course that you have selected it.

/B2S

Edit: For zsh users, run $ rehash to refresh the hash in its entirety.

1
  • 1
    Well, I did not even know about existence of that mechanism. Thank you! Jul 16, 2012 at 12:53
0

I have the same issue, and this is not the correct solution - i'm hoping someone will chime in with one. For the time being, call it directly:

$ gcc-mp-4.7 -v
Using built-in specs.
COLLECT_GCC=gcc-mp-4.7
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin11/4.7.0/lto-wrapper
Target: x86_64-apple-darwin11
    Configured with: ../gcc-4.7.0/configure --prefix=/opt/local --build=x86_64-apple-darwin11 --enable-languages=c,c++,objc,obj-c++,lto,fortran,java --libdir=/opt/local/lib/gcc47 --includedir=/opt/local/include/gcc47 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.7 --with-libiconv-prefix=/opt/local --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.7 --with-gxx-include-dir=/opt/local/include/gcc47/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-ppl=/opt/local --with-cloog=/opt/local --enable-cloog-backend=isl --enable-stage1-checking --disable-multilib --enable-lto --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --with-pkgversion='MacPorts gcc47 4.7.0_3'
Thread model: posix
gcc version 4.7.0 (MacPorts gcc47 4.7.0_3) 

Hope that helps until a permanent solution is found

You must log in to answer this question.

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