[Haskell-cafe] creating standalone executable with haskell

Niklas Hambüchen mail at nh2.me
Tue Mar 5 12:33:46 UTC 2019


The two topics of creating standalone executables, and you not being a system admin, are very separate and don't have much to do with each other.

On the admin topic:
You can set up a full Haskell build environment in your home directory even if you are not an admin.

On the standalone executable topic:
Most Haskell compiled executables can easily run on other Linux systems.
In the default build, a Haskell executable has only a few runtime dependencies via dynamic linking. Here's and example for a HelloWorld program when compiled with `ghc --make`:

    % ldd Hello
	linux-vdso.so.1 =>  (0x00007ffcd9dea000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f3799dcd000)
	libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f3799b4d000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f3799945000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f3799741000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f3799524000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f379915a000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f379a0d6000)

As you can see, a few C libraries must be present on the system.
They are already present on most systems.
Again, you don't need to be admin to get those; if they are missing, you can also ship them along with your executable and set LD_LIBRARY_PATH.

In general, executables created this way on one Linux flavour work reasonably well on other Linux flavours, but not always.
And example (if I remember correctly) where it doesn't work, is Centos 6 vs. newer Debian; one has libgmp.so.3 and one libgmp.so.6.
This means that if you are using the default dynamic linking of C dependencies, you may have to ship "a few" (usually two) flavours of your executable.
In general, executables created on one OS version work well on newer ones, e.g. something created on Ubuntu 16.04 will work well on newer Ubuntus.

You can also link everything statically.
Then your executable should work on any Linux system.
But you need to learn a few more things to do so; I try to make it as convenient as possible with my project
    https://github.com/nh2/static-haskell-nix/

Niklas


More information about the Haskell-Cafe mailing list