haskellhmatrix

hMatrix breaks in a file, what could be the cause?


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)

Solution

  • 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.