Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell Static vs Dynamic Linking in Deployment

Why doesn't cabal install use the flag --enable-shared by default? I've notice that trivial programs when compiled without this flag, get huge in file size. Is there a connection? Is this a design choice related to how Haskell programs are ment to be easily deployed in a single self-contained binary?

like image 904
Nordlöw Avatar asked Oct 21 '11 19:10

Nordlöw


1 Answers

I think it has to do with lack of support. However, I can't get a straight answer as to whether or not GHC currently supports dynamic linking. The GHC wiki page SharedLibraries/PlatformSupport is two years old.

On Windows, I tried building a whole bunch of packages with --enable-shared, including a simple program I wrote that uses http-enumerator to download from a URL every 30 seconds. When I ran the program (after putting all the DLLs in a folder with my program), it segfaulted after a few seconds. When I compiled with --threaded, it segfaulted immediately.

I tried this in GHC 7.0.3. A documentation page for that version says:

Making Haskell libraries into DLLs doesn't work on Windows at the moment; we hope to re-instate this facility in the future (see Section 4.12, “Using shared libraries”). ...

This notice does not appear in later versions.


By the way there's another hassle to static binaries besides code size. GHC uses GMP for its big integer support. GMP is licensed under the LGPL. This means that if you need to distribute a proprietary binary, or if you have a dependency that is not GPL-compatible (e.g. OpenSSL), you will need to distribute your object files to comply with GMP's license. Either that, or find a way to get libgmp to be dynamically linked. I would like to know how to do that.

like image 82
Joey Adams Avatar answered Sep 27 '22 20:09

Joey Adams