Installing Ghc Binaries on Linux (Can't Find Libgmp.So)

Installing ghc binaries on Linux (can't find libgmp.so)

You either add /usr/local/lib and/or /usr/local/lib64 to $LD_LIBRARY_PATH, or add them to /etc/ld.so.conf, or (since you already have /usr/lib64/libgmp.so.3) add a missing symbolic link:

cd /usr/lib64
sudo ln -s libgmp.so.3 libgmp.so

(and perhaps the same for /usr/lib).

Note that /usr/lib64/libgmp.so.3 might be a different version from /usr/local/lib64/libgmp.so, make sure ghc can actually be used with the former.

symlink from libgmp.so to libgmp.so.10

In case anyone didn't see @vivian's answer:

apt-get install libgmp-dev

I had the same problem, and it totally work for my ubuntu

Haskell GHC create executable not depending on GMP?

I'm not at all sure of this, but it seems likely that you can do it by telling GHC to use integer-simple instead of integer-gmp when you build GHC. Specifically, configure INTEGER_LIBRARY=integer-simple. See mk/config.mk.in in the GHC source tree.

Haskell program built on Ubuntu 11.10 doesn't run on Ubuntu 10.04

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.

Statically link GMP to an Haskell application using GHC (+ LLVM)

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.

Moving a compiled Haskell program

Linux behaves just like Windows in this regard. If you compile a Haskell executable on Linux, it will run on any Linux distribution with the right libraries. The problem is that in Windows, the Haskell executables aren't compiled with a dynamic version of libgmp; they are compiled with a static version (so that the library is compiled into the executable) exactly because it can be so difficult to handle dlls on Windows when distributing executables. It is comparably easy to handle the installation of new libraries on Linux.

What you can do is to copy the libgmp.so.10 (which might be a symbolic link to a different file) out of /usr/lib into the same directory as your executable. You can then set the LD_LIBRARY_PATH environment variable to ".", meaning the current directory, before launching your executable. This will make Linux look for libraries in the same directory as executables that it launches, making it find the library. This can be done with a launcher script:

#!/bin/sh
export LD_LIBRARY_PATH=.
`dirname "$0"`/myexecutable "$@"

Saving this script and marking it as executable with chmod +x myscript will make your executable work.

You can use the ldd command to check what other libraries your executable might need and that aren't on the target system.

Do ghc-compiled binaries require GHC or are they self-contained?

GHC does produce stand-alone binaries that do not require GHC itself to be installed, however they do link against some dynamic libraries, most notably libgmp. The remaining libraries are commonly found out of the box on most Linux systems. I believe the situation is similar on Windows.

You can check which dynamic libraries you depend on using ldd on Linux. Here's what I get on Ubuntu Natty for a simple Hello World program:

$ echo 'main = putStrLn "Hello World"' > Hello.hs                                                   
$ ghc --make Hello.hs
[1 of 1] Compiling Main ( Hello.hs, Hello.o )
Linking Hello ...
$ ldd Hello
linux-vdso.so.1 => (0x00007fffe45ff000)
libgmp.so.3 => /usr/lib/libgmp.so.3 (0x00007f8874cf9000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f8874a74000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f887486b000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f8874667000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f88742d3000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f88740b4000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8874f7a000)


Related Topics



Leave a reply



Submit