MacOS – How to link back to the correct C compiler

finkgccmacosxcode

While trying to install fink-0.38.4 I get the ERROR: There is no C compiler on your system. Make sure that the Developer Tools are installed.

I have got errors about missing a C compiler while trying to install some other things too, but I don't remember which packets that were.

I am a designer and need to install a packet called Emokit, but I am totally oblivious to all these open source things I had to install. I am in way over my head, which is why I made a giant mess. To name some stuff I have installed in the last couple of days: MacPorts, Homebrew, Xcode, X11, FoxToolkit, hidapi (maybe, I am not sure if I installed this correctly or not), python, cython, and a couple more and some libraries as well. While doing this I have learned what some things are. I know now that MacPorts and Homebrew serve a similar purpose and having them both is making trouble. However I don't dare to delete one of them because I think some stuff relies on them.

I have multiple versions of GCC, but because some installations wanted a different version, I tried to switch from one version to another version some times. It sometimes worked and sometimes didn't. I forgot how I changed it and now I can't seem to change it back.

I have made a mess and now I have no clue at all on how to fix it.

I am running OS X 10.10.3.

echo $PATH gives (in a list for easier reading)

/usr/local/bin/gcc:
/usr/bin/cc:
/usr/local/bin:
/usr/bin/gcc:
/usr/local/bin:
/Applications/Xcode.app/Contents/Developer/usr/bin:
/Library/Frameworks/Python.framework/Versions/3.4/bin:
/Users/rick/.cabal/bin:
/Applications/ghc-7.10.1.app/Contents/bin:
/Users/rick/.cabal/bin:
/Applications/ghc-7.10.1.app/Contents/bin:
/opt/local/bin:
/opt/local/sbin:
/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/opt/X11/bin

gcc -v gives

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/lto-wrapper
Target: x86_64-apple-darwin14.0.0
Configured with: ../gcc-4.9-20141029/configure --enable-languages=c++,fortran
Thread model: posix
gcc version 4.9.2 20141029 (prerelease) (GCC) 

whereis gcc gives me nothing at the moment. This used to be /usr/bin/gcc

which gcc gives /usr/local/bin/gcc

ls -al $(dirname $(which gcc)) | grep 'gcc\|g++\|c++' (I have no clue what this does actually) gives:

lrwxr-xr-x    1 rick  admin       41 May  7 10:43 aot-compile-4.7 -> ../Cellar/gcc47/4.7.4/bin/aot-compile-4.7
lrwxr-xr-x    1 rick  admin       46 May  7 14:07 c++-4.2 -> ../Cellar/apple-gcc42/4.2.1-5666.3/bin/c++-4.2
lrwxr-xr-x    1 rick  admin       33 May  7 10:43 c++-4.7 -> ../Cellar/gcc47/4.7.4/bin/c++-4.7
lrwxr-xr-x    1 rick  admin       33 May  7 16:11 c++-4.9 -> ../Cellar/gcc/4.9.2_1/bin/c++-4.9
lrwxr-xr-x    1 rick  admin       46 May  7 14:07 cpp-4.2 -> ../Cellar/apple-gcc42/4.2.1-5666.3/bin/cpp-4.2
lrwxr-xr-x    1 rick  admin       33 May  7 10:43 cpp-4.7 -> ../Cellar/gcc47/4.7.4/bin/cpp-4.7
lrwxr-xr-x    1 rick  admin       33 May  7 16:11 cpp-4.9 -> ../Cellar/gcc/4.9.2_1/bin/cpp-4.9
-rwxr-xr-x    1 root  wheel  1166504 Nov  3  2014 g++
lrwxr-xr-x    1 rick  admin       46 May  7 14:07 g++-4.2 -> ../Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2
lrwxr-xr-x    1 rick  admin       33 May  7 10:43 g++-4.7 -> ../Cellar/gcc47/4.7.4/bin/g++-4.7
lrwxr-xr-x    1 rick  admin       33 May  7 16:11 g++-4.9 -> ../Cellar/gcc/4.9.2_1/bin/g++-4.9
lrwxr-xr-x    1 rick  admin       43 May  7 10:43 gappletviewer-4.7 -> ../Cellar/gcc47/4.7.4/bin/gappletviewer-4.7
lrwxr-xr-x    1 rick  admin       36 May  1 13:46 gc++filt -> ../Cellar/binutils/2.25/bin/gc++filt
lrwxr-xr-x    1 rick  admin       40 May  7 10:43 gc-analyze-4.7 -> ../Cellar/gcc47/4.7.4/bin/gc-analyze-4.7
-rwxr-xr-x    1 root  wheel  1166328 Nov  3  2014 gcc
lrwxr-xr-x    1 rick  admin       46 May  7 14:07 gcc-4.2 -> ../Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2
lrwxr-xr-x    1 rick  admin       33 May  7 10:43 gcc-4.7 -> ../Cellar/gcc47/4.7.4/bin/gcc-4.7
lrwxr-xr-x    1 rick  admin       33 May  7 16:11 gcc-4.9 -> ../Cellar/gcc/4.9.2_1/bin/gcc-4.9
-rwxr-xr-x    1 root  wheel    43016 Nov  3  2014 gcc-ar
lrwxr-xr-x    1 rick  admin       36 May  7 10:43 gcc-ar-4.7 -> ../Cellar/gcc47/4.7.4/bin/gcc-ar-4.7
lrwxr-xr-x    1 rick  admin       36 May  7 16:11 gcc-ar-4.9 -> ../Cellar/gcc/4.9.2_1/bin/gcc-ar-4.9
-rwxr-xr-x    1 root  wheel    42992 Nov  3  2014 gcc-nm
lrwxr-xr-x    1 rick  admin       36 May  7 10:43 gcc-nm-4.7 -> ../Cellar/gcc47/4.7.4/bin/gcc-nm-4.7
lrwxr-xr-x    1 rick  admin       36 May  7 16:11 gcc-nm-4.9 -> ../Cellar/gcc/4.9.2_1/bin/gcc-nm-4.9
-rwxr-xr-x    1 root  wheel    43000 Nov  3  2014 gcc-ranlib
lrwxr-xr-x    1 rick  admin       40 May  7 10:43 gcc-ranlib-4.7 -> ../Cellar/gcc47/4.7.4/bin/gcc-ranlib-4.7
lrwxr-xr-x    1 rick  admin       40 May  7 16:11 gcc-ranlib-4.9 -> ../Cellar/gcc/4.9.2_1/bin/gcc-ranlib-4.9
lrwxr-xr-x    1 rick  admin       33 May  7 10:43 gcj-4.7 -> ../Cellar/gcc47/4.7.4/bin/gcj-4.7
lrwxr-xr-x    1 rick  admin       40 May  7 10:43 gcj-dbtool-4.7 -> ../Cellar/gcc47/4.7.4/bin/gcj-dbtool-4.7
lrwxr-xr-x    1 rick  admin       34 May  7 10:43 gcjh-4.7 -> ../Cellar/gcc47/4.7.4/bin/gcjh-4.7
lrwxr-xr-x    1 rick  admin       47 May  7 14:07 gcov-4.2 -> ../Cellar/apple-gcc42/4.2.1-5666.3/bin/gcov-4.2
lrwxr-xr-x    1 rick  admin       34 May  7 10:43 gcov-4.7 -> ../Cellar/gcc47/4.7.4/bin/gcov-4.7
lrwxr-xr-x    1 rick  admin       34 May  7 16:11 gcov-4.9 -> ../Cellar/gcc/4.9.2_1/bin/gcov-4.9
lrwxr-xr-x    1 rick  admin       34 May  7 16:11 gfortran -> ../Cellar/gcc/4.9.2_1/bin/gfortran
lrwxr-xr-x    1 rick  admin       51 May  7 14:07 gfortran-4.2 -> ../Cellar/apple-gcc42/4.2.1-5666.3/bin/gfortran-4.2
lrwxr-xr-x    1 rick  admin       38 May  7 10:43 gfortran-4.7 -> ../Cellar/gcc47/4.7.4/bin/gfortran-4.7
lrwxr-xr-x    1 rick  admin       38 May  7 16:11 gfortran-4.9 -> ../Cellar/gcc/4.9.2_1/bin/gfortran-4.9
lrwxr-xr-x    1 rick  admin       33 May  7 10:43 gij-4.7 -> ../Cellar/gcc47/4.7.4/bin/gij-4.7
lrwxr-xr-x    1 rick  admin       34 May  7 10:43 gjar-4.7 -> ../Cellar/gcc47/4.7.4/bin/gjar-4.7
lrwxr-xr-x    1 rick  admin       40 May  7 10:43 gjarsigner-4.7 -> ../Cellar/gcc47/4.7.4/bin/gjarsigner-4.7
lrwxr-xr-x    1 rick  admin       36 May  7 10:43 gjavah-4.7 -> ../Cellar/gcc47/4.7.4/bin/gjavah-4.7
lrwxr-xr-x    1 rick  admin       38 May  7 10:43 gkeytool-4.7 -> ../Cellar/gcc47/4.7.4/bin/gkeytool-4.7
lrwxr-xr-x    1 rick  admin       43 May  7 10:43 gnative2ascii-4.7 -> ../Cellar/gcc47/4.7.4/bin/gnative2ascii-4.7
lrwxr-xr-x    1 rick  admin       35 May  7 10:43 gorbd-4.7 -> ../Cellar/gcc47/4.7.4/bin/gorbd-4.7
lrwxr-xr-x    1 rick  admin       35 May  7 10:43 grmic-4.7 -> ../Cellar/gcc47/4.7.4/bin/grmic-4.7
lrwxr-xr-x    1 rick  admin       35 May  7 10:43 grmid-4.7 -> ../Cellar/gcc47/4.7.4/bin/grmid-4.7
lrwxr-xr-x    1 rick  admin       42 May  7 10:43 grmiregistry-4.7 -> ../Cellar/gcc47/4.7.4/bin/grmiregistry-4.7
lrwxr-xr-x    1 rick  admin       40 May  7 10:43 gserialver-4.7 -> ../Cellar/gcc47/4.7.4/bin/gserialver-4.7
lrwxr-xr-x    1 rick  admin       40 May  7 10:43 gtnameserv-4.7 -> ../Cellar/gcc47/4.7.4/bin/gtnameserv-4.7
lrwxr-xr-x    1 rick  admin       68 May  7 14:07 i686-apple-darwin11-cpp-4.2.1 -> ../Cellar/apple-gcc42/4.2.1-5666.3/bin/i686-apple-darwin11-cpp-4.2.1
lrwxr-xr-x    1 rick  admin       68 May  7 14:07 i686-apple-darwin11-g++-4.2.1 -> ../Cellar/apple-gcc42/4.2.1-5666.3/bin/i686-apple-darwin11-g++-4.2.1
lrwxr-xr-x    1 rick  admin       68 May  7 14:07 i686-apple-darwin11-gcc-4.2.1 -> ../Cellar/apple-gcc42/4.2.1-5666.3/bin/i686-apple-darwin11-gcc-4.2.1
lrwxr-xr-x    1 rick  admin       73 May  7 14:07 i686-apple-darwin11-gfortran-4.2.1 -> ../Cellar/apple-gcc42/4.2.1-5666.3/bin/i686-apple-darwin11-gfortran-4.2.1
lrwxr-xr-x    1 rick  admin       38 May  7 10:43 jcf-dump-4.7 -> ../Cellar/gcc47/4.7.4/bin/jcf-dump-4.7
lrwxr-xr-x    1 rick  admin       40 May  7 10:43 jv-convert-4.7 -> ../Cellar/gcc47/4.7.4/bin/jv-convert-4.7
lrwxr-xr-x    1 rick  admin       44 May  7 10:43 rebuild-gcj-db-4.7 -> ../Cellar/gcc47/4.7.4/bin/rebuild-gcj-db-4.7
lrwxr-xr-x    1 rick  admin       59 May  7 10:43 x86_64-apple-darwin14.3.0-c++-4.7 -> ../Cellar/gcc47/4.7.4/bin/x86_64-apple-darwin14.3.0-c++-4.7
lrwxr-xr-x    1 rick  admin       59 May  7 16:11 x86_64-apple-darwin14.3.0-c++-4.9 -> ../Cellar/gcc/4.9.2_1/bin/x86_64-apple-darwin14.3.0-c++-4.9
lrwxr-xr-x    1 rick  admin       59 May  7 10:43 x86_64-apple-darwin14.3.0-g++-4.7 -> ../Cellar/gcc47/4.7.4/bin/x86_64-apple-darwin14.3.0-g++-4.7
lrwxr-xr-x    1 rick  admin       59 May  7 16:11 x86_64-apple-darwin14.3.0-g++-4.9 -> ../Cellar/gcc/4.9.2_1/bin/x86_64-apple-darwin14.3.0-g++-4.9
lrwxr-xr-x    1 rick  admin       59 May  7 10:43 x86_64-apple-darwin14.3.0-gcc-4.7 -> ../Cellar/gcc47/4.7.4/bin/x86_64-apple-darwin14.3.0-gcc-4.7
lrwxr-xr-x    1 rick  admin       61 May  7 10:43 x86_64-apple-darwin14.3.0-gcc-4.7.4 -> ../Cellar/gcc47/4.7.4/bin/x86_64-apple-darwin14.3.0-gcc-4.7.4
lrwxr-xr-x    1 rick  admin       59 May  7 16:11 x86_64-apple-darwin14.3.0-gcc-4.9 -> ../Cellar/gcc/4.9.2_1/bin/x86_64-apple-darwin14.3.0-gcc-4.9
lrwxr-xr-x    1 rick  admin       61 May  7 16:11 x86_64-apple-darwin14.3.0-gcc-4.9.2 -> ../Cellar/gcc/4.9.2_1/bin/x86_64-apple-darwin14.3.0-gcc-4.9.2
lrwxr-xr-x    1 rick  admin       62 May  7 10:43 x86_64-apple-darwin14.3.0-gcc-ar-4.7 -> ../Cellar/gcc47/4.7.4/bin/x86_64-apple-darwin14.3.0-gcc-ar-4.7
lrwxr-xr-x    1 rick  admin       62 May  7 16:11 x86_64-apple-darwin14.3.0-gcc-ar-4.9 -> ../Cellar/gcc/4.9.2_1/bin/x86_64-apple-darwin14.3.0-gcc-ar-4.9
lrwxr-xr-x    1 rick  admin       62 May  7 10:43 x86_64-apple-darwin14.3.0-gcc-nm-4.7 -> ../Cellar/gcc47/4.7.4/bin/x86_64-apple-darwin14.3.0-gcc-nm-4.7
lrwxr-xr-x    1 rick  admin       62 May  7 16:11 x86_64-apple-darwin14.3.0-gcc-nm-4.9 -> ../Cellar/gcc/4.9.2_1/bin/x86_64-apple-darwin14.3.0-gcc-nm-4.9
lrwxr-xr-x    1 rick  admin       66 May  7 10:43 x86_64-apple-darwin14.3.0-gcc-ranlib-4.7 -> ../Cellar/gcc47/4.7.4/bin/x86_64-apple-darwin14.3.0-gcc-ranlib-4.7
lrwxr-xr-x    1 rick  admin       66 May  7 16:11 x86_64-apple-darwin14.3.0-gcc-ranlib-4.9 -> ../Cellar/gcc/4.9.2_1/bin/x86_64-apple-darwin14.3.0-gcc-ranlib-4.9
lrwxr-xr-x    1 rick  admin       59 May  7 10:43 x86_64-apple-darwin14.3.0-gcj-4.7 -> ../Cellar/gcc47/4.7.4/bin/x86_64-apple-darwin14.3.0-gcj-4.7
lrwxr-xr-x    1 rick  admin       64 May  7 10:43 x86_64-apple-darwin14.3.0-gfortran-4.7 -> ../Cellar/gcc47/4.7.4/bin/x86_64-apple-darwin14.3.0-gfortran-4.7
lrwxr-xr-x    1 rick  admin       64 May  7 16:11 x86_64-apple-darwin14.3.0-gfortran-4.9 -> ../Cellar/gcc/4.9.2_1/bin/x86_64-apple-darwin14.3.0-gfortran-4.9

gcc-4.2 -v gives

couldn't understand kern.osversion `14.3.0'
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /Volumes/Media/Builds/gcc-5666.3/build/obj/src/configure --disable-checking --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++,fortran --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)

gcc-4.7 -v gives

Using built-in specs.
COLLECT_GCC=gcc-4.7
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc47/4.7.4/libexec/gcc/x86_64-apple-darwin14.3.0/4.7.4/lto-wrapper
Target: x86_64-apple-darwin14.3.0
Configured with: ../configure --build=x86_64-apple-darwin14.3.0 --prefix=/usr/local/Cellar/gcc47/4.7.4 --enable-languages=c,c++,fortran,java,objc,obj-c++ --program-suffix=-4.7 --with-gmp=/usr/local/opt/gmp4 --with-mpfr=/usr/local/opt/mpfr2 --with-mpc=/usr/local/opt/libmpc08 --with-ppl=/usr/local/opt/ppl011 --with-cloog=/usr/local/opt/cloog-ppl015 --with-system-zlib --enable-version-specific-runtime-libs --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --disable-werror --with-pkgversion='Homebrew gcc47 4.7.4 --with-all-languages --with-nls --with-profiled-build' --with-bugurl=https://github.com/Homebrew/homebrew-versions/issues --enable-plugin --with-ecj-jar=/usr/local/opt/ecj/share/java/ecj.jar --enable-multilib
Thread model: posix
gcc version 4.7.4 (Homebrew gcc47 4.7.4 --with-all-languages --with-nls --with-profiled-build) 

This is the message the install helper (https://github.com/fink/scripts/blob/master/srcinstaller/Install%20Fink.tool#L2) gave me:

Checking package... looks good (fink-0.38.4).
Checking system... i386-apple-darwin14.3.0
This system was not released at the time this Fink release was made. 
Prerelease versions of Mac OS X might work with Fink, but there are no guarantees.
Distribution: 10.10
Architecture: x86_64
Checking cc... not found.
ERROR: There is no C compiler on your system. Make sure that the Developer Tools are installed.
logout

[Process completed]

I don't know what more information to give or if this is way too much info. So please ask if you need anything more.
Probably this stuff contains a lot of mistakes and faulty stuff. I don't understand much about this, but in my head the only way to be able to fix this now is to do a clean install of my OS, which is not really a possibility at the moment because I am in the middle of graduating.
Thanks a lot for your help!

EDIT is below

After deleting a lot of gcc's I tried installing fink again: same error.
I tried running this simple Hello, world! script.

#include <stdio.h>

main()
{
printf(“Hello, world!\n”);
return 0;
}

And trying to compile with gcc gave me the following:

Ricks-MacBook-Pro:downloads rick$ gcc -o hello hello.c
couldn't understand kern.osversion `14.3.0'
hello.c: In function ‘main’:
hello.c:5: error: stray ‘\342’ in program
hello.c:5: error: stray ‘\200’ in program
hello.c:5: error: stray ‘\234’ in program
hello.c:5: error: ‘Hello’ undeclared (first use in this function)
hello.c:5: error: (Each undeclared identifier is reported only once
hello.c:5: error: for each function it appears in.)
hello.c:5: error: ‘world’ undeclared (first use in this function)
hello.c:5: error: expected ‘)’ before ‘!’ token
hello.c:5: error: stray ‘\’ in program
hello.c:5: error: stray ‘\342’ in program
hello.c:5: error: stray ‘\200’ in program
hello.c:5: error: stray ‘\235’ in program
Ricks-MacBook-Pro:downloads rick$ 

Best Answer

Here's the answer to what you ask - how do I find and sort out gcc when multiple copies exist.

  1. which gcc
  2. mdls `which gcc`
  3. mdfind "kMDItemDisplayName == 'gcc'"

The first command shows you the gcc that's in your $PATH variable first. The second lets you inspect the metadata for that file so you can pick a field to use with mdfind.

Now, simply uninstall / delete any gcc you don't really want to maintain or just make your $PATH so that the desired gcc comes up first. I often do this by sym linking whatever gcc I want to /usr/local/bin/ and making that very early in my $PATH


Now for some unsolicited advice. Make a good backup of the Mac as mixing something as old as fink on a new OS is likely to be problematic going forward. Having a good backup frees you to delete fink one weekend when you have spare time to learn what breaks and know you can go back if the move to just homebrew is premature.