16
  1. How can I drop dynamic dependency on libgmp and go from this:

    linux-vdso.so.1 =>  (0x00007fffdccb1000)
    libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007fb01afc1000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb01acc7000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fb01aabe000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fb01a8ba000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb01a69d000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb01a2df000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fb01b249000)
    

    to this (currently desired):

    linux-vdso.so.1 =>  (0x00007fffdccb1000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb01acc7000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fb01aabe000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fb01a8ba000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb01a69d000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb01a2df000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fb01b249000)
    

    in a clean and portable way that just works on all GNU/Linux distributions (and not messing up with BSDs (including OS X))?

  2. Do you see any other dependencies that may cause problems in the currently desired list as given above when distributing a single Haskell binary targeting multiple GNU/Linux distributions?


Notes:

Community
  • 1
  • 1
Cetin Sert
  • 4,497
  • 5
  • 38
  • 76
  • What's your deploy process like? Specifically what's preventing you from deploying libgmp along with your application? What do you mean not messing up on BSDs including OSX? You can't run the same binary on both OSX and Linux. – asm May 10 '12 at 19:50
  • @AndrewMyers I use Cabal for builds. Deploy libgmp? How? I want to support at least Windows, Linux, OS X and FreeBSD. If I need to build a shared/dynamic library version of libgmp for each platform to deploy it along with my app, that is just too much work. Not messing up: a solution that works preferably not only on a single OS; was thinking of someone possibly suggesting using something like `locate libgmp` and use whatever it may return at link time and `locate` behaving differently on different OSes. (Replace `locate` with any other tool here as you wish.) – Cetin Sert May 10 '12 at 20:02
  • It sounds like you're talking about deploying a binary, which you'll have to build for each platform. Since you have to build it for each platform you have to have a version of libgmp for each platform anyway so you can just package this with your binary. Am I missing something about how you're planning to distribute your application? – asm May 10 '12 at 20:36
  • Do you actually need to support fast Integer operations? Will simple-integer not suffice? – Thomas M. DuBuisson May 10 '12 at 20:36
  • 1
    @ThomasM.DuBuisson `simple-integer` does suffice for the time being actually. Do I not have to recompile GHC rather than just my app for being able to use it? – Cetin Sert May 10 '12 at 20:41
  • @ThomasM.DuBuisson and in the near future, I guess we will do cryptography which may need fast `Integer` operations and thus GMP. – Cetin Sert May 10 '12 at 20:42
  • @AndrewMyers Given Platform = OS + Arch, I want to build only once for Linux + x86_64, i.e. I do not want my users to deal with presence, absence of GMP on a particular GNU/Linux distribution. In short I have a single static version of a library somewhere, GHC and my app: I want GHC to statically link the library with my application. That is all :) – Cetin Sert May 10 '12 at 20:45
  • @CetinSert Yes, you must recompile GHC to use simple-integer. – Thomas M. DuBuisson May 10 '12 at 20:57

1 Answers1

15

If you pass -optl-static -optl-pthread to GHC, it'll statically link all the runtime library dependencies, including GMP. Setting ld-options: -static -pthread in your Cabal file should accomplish the same thing.

That means you'll statically link in glibc too, but that probably won't be a problem, although it might increase binary size quite a bit. Using an alternative libc like musl or uClibc should help counteract that, if it's a problem for you.

ehird
  • 40,602
  • 3
  • 180
  • 182
  • 1
    I'm not sure. The last time I statically linked a program with GHC, I got errors relating to pthread symbols if I didn't pass it. It might not be necessary any more. – ehird May 11 '12 at 10:59
  • I just linked an app as statically as possible. **Windows** and **OS X**: `libgmp` is statically compiled. **Linux**: `-static` for `ghc` and `ld` is enough without `-pthread`; `libc` is statically linked but warns about dynamic loading used inside `libc`. **FreeBSD**: always complains about `pthread` symbols whether I use `-pthread` or not. – Cetin Sert May 11 '12 at 11:11
  • I guess I will have to accept that as an answer soon because it works despite the warnings (perhaps only with `glibc`). There seems to be no working way to statically link only `libgmp` without going all the way. – Cetin Sert May 11 '12 at 11:19
  • 1
    [This](http://stackoverflow.com/a/8658468/166732) answer to a question I asked a while ago about deploying Yesod to Heroku may be relevant to your warnings. – asm May 12 '12 at 20:02
  • @AndrewMyers: Right; a situation like that could be avoided by using an alternative libc which doesn't have such a requirement. – ehird May 12 '12 at 20:13