0

I have been using the hMatrix package in the ghci environment, and all works fine (I can for instance import Numeric.LinearAlgebra.HMatrix). However, when I attempt to import and utilise the same things in a script, everything breaks (I truncated the error message slightly for readability (longer list of _base_GHCiIO-errors)). For instance these two lines in a file creates the error(s) below. Does anybody know what could be the cause? I am on mac OS X Yosemite.

import Numeric.LinearAlgebra.HMatrix

main = print ((2><1) [1.0::Float,1.0])

$ ghc 2_12.hs 
[1 of 1] Compiling Main             ( 2_12.hs, 2_12.o )
Linking 2_12 ...
Undefined symbols for architecture x86_64:
  "_iconv", referenced from:
  _hs_iconv in libHSbase-4.7.0.2.a(iconv.o)
 (maybe you meant: _hs_iconv,
  _base_GHCziIOziEncodingziIconv_iconvEncoding9_info ,
  _base_GHCziIOziEncodingziIconv_iconvEncoding8_info,
  _base_GHCziIOziEncodingziIconv_iconvEncoding9_closure ,
  _hs_iconv_open , _hs_iconv_close ,
  "_iconv_close", referenced from:
  _hs_iconv_close in libHSbase-4.7.0.2.a(iconv.o)
 (maybe you meant: _hs_iconv_close)
 "_iconv_open", referenced from:
 _hs_iconv_open in libHSbase-4.7.0.2.a(iconv.o)
 (maybe you meant: _hs_iconv_open)
 "_locale_charset", referenced from:
  _localeEncoding in libHSbase-4.7.0.2.a(PrelIOUtils.o)
 ld: symbol(s) not found for architecture x86_64
 clang: error: linker command failed with exit code 1 (use -v to see     
 invocation)
stian
  • 1,947
  • 5
  • 25
  • 47

1 Answers1

1

You probably have libiconv installed with MacPorts. The definitions in the MacPorts libiconv are (annoyingly) somehow different from the ones in the OS X libiconv. Here is some more explanation.

I had the same problem and my solution was to pass the --extra-lib-dirs=/usr/lib argument to cabal (/usr/lib is where OS X keeps libiconv). You can use cabal configure --extra-lib-dir=/usr/lib before compiling, or most likely also cabal install --extra-lib-dir=/usr/lib. You can also add the extra-lib-dirs statement to your cabal file. /usr/lib is already always included, but normally the MacPorts library directory is searched first: by adding the --extra-lib-dirs argument you make sure that ghc searches /usr/lib before it searches the MacPorts library directory.

Sam van Herwaarden
  • 2,321
  • 14
  • 27
  • I wrote like this ghc --extra-lib-dirs=/usr/lib 2_12.hs, and got ghc: unrecognised flag: --extra-lib-dirs=/usr/lib Usage: For basic information, try the `--help' option. – stian Sep 15 '15 at 11:32
  • 1
    Hmm maybe I remembered wrong and it's not a ghc flag but a cabal configuration option. Please try `cabal configure --extra-lib-dir=/usr/lib` before running ghc and let me know if that works (I will update my answer). – Sam van Herwaarden Sep 15 '15 at 11:34
  • thanks, Yeah I saw the same in that link was just about to post. – stian Sep 15 '15 at 11:35
  • damn, cabal configure --extra-lib-dir=/usr/lib. cabal: No cabal file found. Please create a package description file .cabal – stian Sep 15 '15 at 11:38
  • And what if you `cabal install hmatrix --extra-lib-dirs=/usr/lib`? Then at least hmatrix should be properly linked – Sam van Herwaarden Sep 15 '15 at 11:54
  • I wrote cabal install hmatrix --extra-lib-dirs=/usr/lib --reinstall without any change actually. – stian Sep 15 '15 at 12:05
  • I will try my luck with the bed-and-breakfast package for a while. Sad, I liked the translation of matlab to haskell commands in the hMatrix tutorial. – stian Sep 15 '15 at 12:25
  • @hotGopher: I would recommend that you don't shy away from writing a .cabal file (and I even recommend writing a stack.yaml and using stack because that is even more convenient once you get used to it) - it might fix your problem, hmatrix is a great library, and "cabal init" makes writing a .cabal file very easy. – Sam van Herwaarden Sep 16 '15 at 09:54