4

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?

2
  • 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
    Sep 9, 2011 at 21:18
  • You'd be best off writing a package and having each package build for each different arch and not statically link gmp Nov 10, 2011 at 20:50

3 Answers 3

2

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
  • I am trying to deploy my web app to Heroku Cedar stack. Cedar uses Ubuntu 11.04 and I use 11.10. So, basically I got the same error. But I tried your solution and it raises a new error, mkTextEncoding: invalid argument (Invalid argument). Can you help me out here? Dec 21, 2011 at 7:55
1

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

3
  • But wouldn't it then dynamically link to libgmp3, meaning it won't run on Ubuntu 11.10 and possibly other Linux distributions? You also mention generic libgmp. Is there a way to have the binary use whichever version of libgmp it encounters?
    – FalconNL
    Sep 8, 2011 at 8:01
  • With generic libgmp I meant the generic package, which automatically provides the current version of libgmp. You can't generically link your program because a new major version number means that functionality was dropped in the transition from libgmp3 to libgmp10. Your program would run on Ubuntu 11.10, too, because Ubuntu 11.10 still has libgmp3 available (multiple major versions can be installed in parallel). Summarizing: If -static is a sufficient option for you, that's OK, and if you go with -dynamic, use the oldest reasonable library.
    – thiton
    Sep 8, 2011 at 12:29
  • Just make sure your .deb indicates a dependency on the required version of the dynamic library in its control file.
    – tripleee
    Sep 9, 2011 at 8:43
1

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

2
  • Ah, so on Linux you need to explicitly enable this? I always thought GHC always compiled statically by default. I'll try this when I get home.
    – FalconNL
    Sep 8, 2011 at 8:08
  • Ok, I tried compiling with -static and unfortunately I still get the same error message. Any ideas what I'm doing wrong?
    – FalconNL
    Sep 8, 2011 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.