Take the 2-minute tour ×

I recently installed (from the binary installers) GHC 6.12 and the Haskell Platform 2010.1.0.1 on my Intel MacBook running OS X 10.5.8, and initially, everything worked fine. Edit: I had to install cabal, alex, and happy from source, but after that, everything did seem to work fine. However, I discovered that if I use cabal install to install a package which depends on a MacPorts library (e.g., cabal install --extra-lib-dirs=/opt/local/lib --extra-include-dirs=/opt/local/include gd), things work fine in GHCi, but if I try to compile, I get the error

Linking test ...
Undefined symbols:
  "_iconv_close", referenced from:
      _hs_iconv_close in libHSbase-
  "_iconv", referenced from:
      _hs_iconv in libHSbase-
  "_iconv_open", referenced from:
      _hs_iconv_open in libHSbase-
ld: symbol(s) not found
collect2: ld returned 1 exit status

After some Googling, I found a long Haskell-cafe thread discussing this problem. The upshot seems to be that MacPorts installs an updated version of libiconv, and the binary interface is slightly different from the version included with the system. Consequently, if you try to link with any MacPorts library, the MacPorts libiconv gets linked in too; and since the base library was built to link against a different version of libiconv, things break. I've tried setting LD_LIBRARY_PATH and DYLD_LIBRARY_PATH and adding more flags to try to get it to look at /usr/lib again (e.g. cabal install --extra-lib-dirs=/opt/local/lib --extra-include-dirs=/opt/local/include --extra-lib-dirs=/usr/lib --extra-include-dirs=/usr/include gd), but neither worked. Uninstalling the MacPorts libiconv isn't really an option, since I have a bunch of ports installed which depend on it---including some ports I want Haskell to link to, like gd2.

From what I've seen online, the upshot really seems to be "you're boned": you cannot link against any MacPorts library while compiling with GHC, and there doesn't seem to be a solution. However, that thread was from the end of 2009, so I figure there's a chance that someone has a solution, workaround, ridiculous hack… anything, really. So: does anybody know how to get GHC 6.12 to link against the system libiconv at the same time as it links to libraries from MacPorts? Or, failing that, a way to make linking not break in some other clever way?

share|improve this question
Did you install the binary Haskell Platform, or the MacPorts build? Or the source build? –  Don Stewart Apr 28 '10 at 2:48
Binary installers for both GHC and the Haskell Platform. I'll edit the question to reflect that. –  Antal S-Z Apr 28 '10 at 3:18
I'm getting exactly this problem with a GHC 6.12.3 I've built from source. –  Simon Michael Jul 4 '10 at 18:21
add comment

5 Answers

up vote 6 down vote accepted

I was getting the same error on MacOSX 10.5.8 when I installed haskell-platform-2010.1.0.1-i386 and attempted to compile a haskell program. The solution for me was to add the option "-L/usr/lib" to ghc when compiling the program. I believe this managed to get the linker to first search /usr/lib for the iconv library which resolved the problem for me.

share|improve this answer
I could have sworn I'd tried this, but when I was compiling something using GTK today and getting the same error, I thought I'd give it a shot. Lo and behold, it worked! Thank you! –  Antal S-Z Jun 29 '10 at 21:34
How do you accomplish this when installing things with cabal ? –  Simon Michael Jul 4 '10 at 18:27
A simple "extra-lib-dirs: /usr/lib" in ~/.cabal/config took care of that for me. –  Simon Michael Jul 28 '10 at 14:38
add comment

I made my problems go away by uninstalling MacPorts. You could probably get away with just uninstalling the MacPorts version of libiconv and any library that depends on it.

share|improve this answer
This worked for me as well. HomeBrew seems to be a good alternative to MacPorts. –  Sjoerd Visscher Nov 6 '10 at 13:16
add comment

I'm somewhat ashamed to admit this, but I've had some success with incantations like the following:

LIBRARY_PATH=/usr/lib:/opt/local/lib cabal install --ghc-option="-L/usr/lib" SDL-gfx
share|improve this answer
add comment

This is weird: afaik Platform 2010.1.0.1 does not work on OS X 10.5.8, this has been reported and verified by several people including myself, and more interestingly - by you!

share|improve this answer
That bug indicates that cabal doesn't work---for me, at least, GHC and GHCi worked fine. I had to install cabal, alex, and happy from source; once I did that, everything worked (except for this libiconv error). Good catch, though. –  Antal S-Z Apr 28 '10 at 17:16
add comment

Perhaps this may be better cabal configure --extra-lib-dir=/usr/lib It does resolve the issue on OSX Mountain Lion

share|improve this answer
add comment

Your Answer


