Haskell Static vs Dynamic Linking in Deployment
Asked Answered
C

1

6

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?

Cash answered 21/10, 2011 at 19:56 Comment(3)
ISTR the shared library support is fairly new and doesn't work on all platforms, also makes it harder to distribute executables. And space is cheap, so who cares? There will be a better answer though.Tegantegmen
@luqui: Space may be cheap, but what about bandwidth? What if you need to push updates for your 20MB program over the Internet, to clients with less-than-ideal connectivity?Orth
also see the GHC Docs on "Using shared libraries"Levorotatory
O
4

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.

Orth answered 21/10, 2011 at 20:34 Comment(1)
does this answer still hold as of March 2015?Figural

© 2022 - 2024 — McMap. All rights reserved.