Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GHC 6.12 and MacPorts

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-4.2.0.0.a(iconv.o)
  "_iconv", referenced from:
      _hs_iconv in libHSbase-4.2.0.0.a(iconv.o)
  "_iconv_open", referenced from:
      _hs_iconv_open in libHSbase-4.2.0.0.a(iconv.o)
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?

like image 774
Antal Spector-Zabusky Avatar asked Apr 28 '10 01:04

Antal Spector-Zabusky


3 Answers

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.

like image 78
David Powell Avatar answered Oct 23 '22 03:10

David Powell


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.

like image 1
tibbe Avatar answered Oct 23 '22 03:10

tibbe


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
like image 1
Iain Avatar answered Oct 23 '22 04:10

Iain