ssledz blog

Everything should be made as simple as possible, but no simpler.

Static Linking With Ghc

In order to compile a given source code using static linking

1
2
-- Main.hs
main = putStrLn "Hello World!"

there is a need to pass two additional flags to ghc like

  • -optl-static
  • -optl-pthread
1
$ ghc -optl-static -optl-pthread --make Main

then

1
2
3
4
$ file Main
Main: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked,
for GNU/Linux 3.2.0, BuildID[sha1]=62d1682f378af2f994758e737ba9dc0b24fc06aa,
with debug_info, not stripped

Comments