8

I have been trying to install Haskell Platform and cabal-install installed on Linux in user-space on a system that doesn't have the GNU Multi-Precision package (GMP) installed.

I managed to get GHC-6.12.1 installed and GHCi working by setting up LB_LIBRARY_PATH to point at the lib directory where I installed GMP, but then ran into problems in the next step, getting cabal-install to work. It kept trying to (statically) link to GMP.

This fails because the GMP is not installed in the system and ld hasn't a clue where to find the libraries, and there is no environment variable (that I am aware of) that can tell ld where to find the user-installed GMP, and (apparently) no way of telling configuring Cabal to supply the relevant -L flag.

After much fruitless searching and hacking attempts I hit on the absurdly simple idea of installing my own ld shell script that invokes the system ld with the appropriate -L flag.

This is shell scripting 101, of course:

#!/bin/sh
/usr/bin/ld -L$HOME/gnu/lib "$@"

With this script installed in a directory on my PATH ahead of /usr/bin all the problems seem to have gone away.

hammar
  • 138,522
  • 17
  • 304
  • 385
chrisdornan
  • 217
  • 3
  • 9

1 Answers1

10

Basically, your ghc is not working yet. Yes, it can compile things, but it cannot link programs because it needs to link them to gmp.

What we can do is to edit some core package, e.g. the rts package, so that ghc will always use the right -L flag:

ghc-pkg describe rts > rts.pkg
vi rts.pkg                      # add the gmp dir to the `library-dirs` field
sudo ghc-pkg update rts.pkg
Duncan Coutts
  • 786
  • 1
  • 6
  • 9
  • 1
    For those people who've installed GHC in a user directory, they'll be able to execute the last command with sudo. When I manually edited the rts.pkg, I didn't know what kind of field separater cabal used, so I just put the extra library directory on its own line after the original. – pyrachi Dec 19 '10 at 01:24
  • 3
    The separator for these library dirs is just space. – Larry LIU Xinyu Oct 17 '13 at 08:04
  • Copy the libgmp.so to one of the `include-dirs` e.g. `/home/dilawar/bin/lib/ghc-7.8.3/rts-1.0`. It worked for me. – Dilawar Nov 05 '14 at 11:05