GHC in MacPorts

MacPorts, formerly known as DarwinPorts, is a mixed blessing. Sometimes, it performs: it compiles and builds the software requested, and it just works. At other times, one or more of the packages is broken. It literally changes day-to-day: stuff that used to work may not work any more when you want to install it.

I’d had some problems with my installation of MacPorts recently—they appeared to be related to different versions of gcc—so I decided to move aside the existing installation and rebuild everything from scratch.

One port that just wouldn’t work was the GHC Haskell package. Installation failed every time with a perplexing error:

configure: error: C compiler cannot create executables
See `config.log' for more details.

Well, that wasn’t true: I spent yesterday afternoon writing a program in C, and I definitely managed to compile and run it! I dug into the log file mentioned, and found one repeated error that seemed promising:

dyld: Library not loaded: /usr/i686-apple-darwin8/lib/libgcc_s.1.dylib
  Referenced from: /usr/bin/gcc

It wasn’t surprising that it didn’t find the library: it wasn’t there. In fact, the desired file is located in /usr/lib.

The fix is to add that path to the DYLD_FALLBACK_LIBRARY_PATH environment variable, which can be done by editing one line in the GHC Portfile:

Change the last line of:

configure.env LDFLAGS="-L/usr/lib -L${prefix}/lib" \
              CPPFLAGS="-I${prefix}/include" \
              CFLAGS="-I${prefix}/include" \
              DYLD_FALLBACK_LIBRARY_PATH=${prefix}/lib

to:

DYLD_FALLBACK_LIBRARY_PATH=${prefix}/lib:/usr/lib

... and then wait a few hours while it compiles. No, really: you could build an entire operating system in less time than it takes to compile just this programming language. I went to bed; when I woke up it was finished.

Comments

Skip to the comment form

  1. Emil

    Wrote at 2007-05-13 19:59 UTC using Firefox 2.0.0.3 on Mac OS X:

    Thanks a lot! I did not have the energy to go through the log file :-)
  2. Sean B. Palmer

    Wrote at 2007-09-07 14:24 UTC using Firefox 2.0.0.6 on Mac OS X:

    Thanks: it looks like a lot of people are having this problem, but this is the only clear explanation and fix which works that I could find using Google. Well done old chap.

Leave a comment

Please read the comment guidelines before posting. Comments are Gravatar-enabled. Your email address will not be published.

To prove that you’re human, type human in the Bot check field.

Trying to post some program output or a long code sample? Please use a paste service and link to it instead.