Skip to content
Build a GHC which produces shared libraries without runtime Haskell dependencies
Dockerfile Makefile
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
patches Initial commit. Oct 1, 2019
.gitignore Initial commit. Oct 1, 2019
Dockerfile Initial commit. Oct 1, 2019
LICENSE Add license. Oct 1, 2019
Makefile Initial commit. Oct 1, 2019 Add note about (not) using ghc-sd with cabal. Oct 2, 2019


Dockerfile for building a GHC package for Debian/Ubuntu which supports statically linking Haskell dependencies into dynamic (e.g. .so) libraries.

Supported GHC versions:

  • 8.6.5


Install docker, run make, wait. When make is done, you'll find your package in the deb subdirectory.

To build a shared library with all Haskell dependencies statically linked, use the following GHC flags:

-fPIC -shared -optl-Wl,-Bstatic -lHSrts -lCffi -optl-Wl,-Bdynamic -lrt -lpthread

Unfortunately, cabal has its own ideas about what flags to pass to the linker, which makes it unable to produce shared libraries with statically linked Haskell dependencies even when properly setting ld-options and/or ghc-options.


Because it's nice to be able to distribute Haskell .so files without having to also distribute the roughly seven million it ends up depending on with dynamic linking.

With the right flags, this GHC build produces .so files that are only dependent on the standard system libraries libc, libm, librt and libpthread, plus libgmp.

You can’t perform that action at this time.