How to specify which GCC for MacPorts to use?

5

2

I compiled GCC 4.4.3 and installed it in /usr/local/bin, but whenever I install a port via MacPorts 1.8.2 the verbose output says MacPorts is using /usr/bin/gcc-4.2:

checking for gcc... /usr/bin/gcc-4.2

How do I make MacPorts find my own GCC 4.4.3? Here is my existing path:

/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/lib:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

I am running Mac OS X 10.6.2 Snow Leopard.

hpy

Posted 2010-03-28T18:23:02.930

Reputation: 5 269

Answers

3

First answer: Don't! In my experience, GCC 4.4.3 will not work properly on Snow Leopard. It will cause problems with zero-length strings.

Second answer: edit your symbolic links in /usr/bin to refer to the 4.4 stuff. Here's a script I wrote to do so:

rm /usr/bin/c++ 
ln -s /usr/bin/c++-${1} /usr/bin/c++
rm /usr/bin/cc
ln -s /usr/bin/cc-${1} /usr/bin/cc
rm /usr/bin/cpp
ln -s /usr/bin/cpp-${1} /usr/bin/cpp
rm /usr/bin/g++
ln -s /usr/bin/g++-${1} /usr/bin/g++
rm /usr/bin/gcc
ln -s /usr/bin/gcc-${1} /usr/bin/gcc
rm /usr/bin/gcov
ln -s /usr/bin/gcov-${1} /usr/bin/gcov

I called it chgCver, so to change my compiler to 4.4, I'd type chgCver 4.4. Of course, before you run this, you'll also need to make sure that, for example, c++-4.4 points to the correct place (probably /opt/local/bin/gcc-mp-4.4), etc. I can give you more specifics, if you're inclined to ignore my first and third answers.

Third answer: Don't! (See first answer.)

Ben Hocking

Posted 2010-03-28T18:23:02.930

Reputation: 546

Didn't know GCC 4.4.3 had this problem, thanks! – hpy – 2010-03-28T19:10:38.193

3No need for this, just use gcc_select. – Adam Rosenfield – 2010-12-27T14:04:41.183

3As we're talking about using MacPorts there's the "gcc_select" port that will do the same job and a little more. – anddam – 2011-03-26T06:00:06.380

7

MacPorts is using Apple supplied compilers wherever possible as they are highly patched for the platform. For example, they allow to build for multiple architectures by specifying -arch flags which is not possible with FSF gcc.

If you change symlinks in /usr/bin/cc, MacPorts will still try to use flags which are only understood by the Apple version. This could make it impossible to compile anything using MacPorts.

Just trust the MacPorts developers that using Apple provided compilers is the best way.

raimue

Posted 2010-03-28T18:23:02.930

Reputation: 610

7

Set configure.compiler variable in Portfile accordingly:

configure.compiler    macports-gcc-4.3

or append configure.compiler=macports-gcc-4.3 to your command.

cf. this wiki page.

anddam

Posted 2010-03-28T18:23:02.930

Reputation: 425

Is this still known to cause problems like in the other answer? Thanks! – hpy – 2010-12-11T06:08:05.223

2I wasn't able to determine what the problems were, first Google result for "gcc 4.4.3 zero lenght string problem" is this very same superuser question. – anddam – 2011-03-26T06:03:05.470