mkTextEncoding error when running Haskell program compiled on Mac

215 Views Asked by At

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!

1

There are 1 best solutions below

0
On

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.