1

I'm using Haskell Platform 2011.2.0.1 installed via Homebrew. I have set up a cabalised project with relevant dependencies all defined. The executable does nothing more than to print out the arguments passed in to it. The program compiles and links correctly, but when the program ...

Main.hs:

  main = do
    args <- getArgs
    putStrLn "Here are your arguments!:"
    forM_ args putStrLn

... is run, I get ...

Trace:

$ cabal configure
Resolving dependencies...
Configuring foo-0.1...

$ cabal build
Preprocessing executables for foo-0.1...
Preprocessing test suites for foo-0.1...
Building foo-0.1...

$ dist/build/foobar/foobar some arguments
foobar: mkTextEncoding: failed (Unknown error: 0)
FAIL: 1

The relevant part of my PATH variable reads: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/texbin:/usr/X11/bin

I'm thinking that this is a problem related to libiconv. Any ideas? Thanks!

fatuhoku
  • 4,815
  • 3
  • 30
  • 70
  • I'm not an expert in the matter, but problems with iconv on Mac are quite common. As far as I gathered, there are two iconvs, the system one and the macports one, and they're incompatible, stuff wanting the one can't work with the other. If your google-fu is stronger than mine, a search would likely turn up possible solutions (I didn't find anything, but I seem to recall fixing strategies occasionally posted on the mailing lists). – Daniel Fischer Nov 27 '11 at 13:57
  • @DanielFischer is correct, although the problems usually manifest during linking. The generally-accepted solution to iconv problems is to add this flag when configuring: `--extra-lib-dir=/usr/lib`. Then cabal will find the system iconv first. This works unless you're also linking to a library which requires the macports iconv (many libraries have iconv as a dependency, but few seem to actually use it). More information at http://blog.omega-prime.co.uk/?p=96 . Personally I prefer the third solution (self-compiling GHC). But do you even need macports? – John L Nov 28 '11 at 09:08
  • Thank you for both your help, and very very prompt replies. I found out what was wrong thanks to John's comments about --extra-lib-dir. – fatuhoku Dec 03 '11 at 00:37

1 Answers1

1

Thanks to Daniel and John's inputs, I found out the solution to my own problem.

In my case, foobar: mkTextEncoding: failed (Unknown error: 0) FAIL: 1 was caused by a dodgy linkage to the gd library.

The issue can be seen by inspecting the binary's used libraries.

$ otool dist/build/foobar/foobar -L
foobar:
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
    libgd.dylib (compatibility version 0.0.0, current version 0.0.0)
    /usr/local/lib/libpng12.0.dylib (compatibility version 47.0.0, current version 47.0.0)
    /usr/local/lib/libjpeg.8.dylib (compatibility version 12.0.0, current version 12.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11)
    /usr/local/lib/libfontconfig.1.dylib (compatibility version 6.0.0, current version 6.4.0)
    /usr/local/lib/libfreetype.6.dylib (compatibility version 15.0.0, current version 15.0.0)
    /usr/lib/libexpat.1.dylib (compatibility version 7.0.0, current version 7.2.0)
    /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)

The odd line out of course shows us the culprit:

    libgd.dylib (compatibility version 0.0.0, current version 0.0.0)

The version and location looks odd. Removing the dependency on gd made my program work again. However, I've not managed to getlibgd working on my Mac. That problem is out of the scope of this question.

fatuhoku
  • 4,815
  • 3
  • 30
  • 70