4
votes

I'm trying to provide the users of my program with some Linux binaries in addition to the current Windows ones, so I installed Ubuntu 11.10 (since the haskell-platform package on 11.04 is still the 2010 version). When I try to run the resulting binary on Ubuntu 10.04, however, I get the message that it cannot find libgmp.so.10. Checking /usr/lib reveals that 10.04 comes with libgmp.so.3 whereas 11.10 has libgmp.so.10. It would appear therefore that GHC is linking to libgmp dynamically rather than statically, which I thought was the default.

Is there any way to tell GHC to statically include libgmp in the binary? If not, is there some other solution that does not require the user to install a different version of libgmp?

3
Unless I'm mistaken, the reason why libgmp is linked dynamically by default, is that linking it statically forces you to distribute the resulting executable under the GPL license.hammar
You'd be best off writing a package and having each package build for each different arch and not statically link gmpalternative

3 Answers

2
votes

It turns out that in order to statically link the binary the -static flag is not sufficient. Instead, use:

ghc -static -optl-static -optl-pthread --make yourfile.hs

Using this, my binaries ran correctly on both versions of Ubuntu.

1
votes

Often, the old libgmp packages are available as well; that is, make your program depend on the libgmp3c2 package instead of a generic libgmp or libgmp10. This can often be achieved by compiling with an earlier version of GHC or the gmp lib (e.g. install libgmp3-dev instead of libgmp10-dev).

1
votes

You have the ghc option -static to link statically against the libraries.