How to produce a statically linked binary with GHC?

Agent Zhang agentzh at
Fri Aug 15 02:30:56 EDT 2008

2008/8/15 Nicola Squartini <tensor5 at>
> So I run that gcc command manually adding -lpthread at the end of it end it works,
>  I get the static binary. Isn't it strange? It could be a gcc problem.

Well, it needn't be that hacky ;) The following command works for me
and it does essentially the same thing:

   ghc -i -static -optl-static -optl-pthread -funbox-strict-fields
-fwarn-incomplete-patterns -isrc --make Main -o bin/restyscript

Please note that without -optl-pthread option, I'll get exactly the same errors:

Linking bin/restyscript ...
In function `timer_create':
(.text+0x117): undefined reference to `pthread_once'
In function `timer_create':

-lpthread needs to be put to the end of the argument list to help gcc
or ld solve the symbols properly.

Hope this helps ;)


More information about the Glasgow-haskell-users mailing list