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.