large binaries

Andreas Wollschlaeger andy@chindogu.de
Thu, 18 Jul 2002 21:45:02 +0200


On Thursday 18 July 2002 21:09, Jon Cast wrote:
> Abraham Egnor <aegnor@antioch-college.edu> wrote:
> > This is something I just noticed...
> >
> > hello.hs:
> > module Main(main) where
> >
> > main = putStr "Hello world!\n"
> >
> > hello.c:
> > #include <stdio.h>
> >
> > int main(void)
> > {
> >   printf("Hello world!\n");
> >   return 0;
> > }
> >
> > [abe@shiva:~/src/test] $ ghc hello.hs -o hello_hs
> > [abe@shiva:~/src/test] $ gcc hello.c -o hello_c
> > [abe@shiva:~/src/test] $ ls -l hello_*
> > -rwxr-xr-x    1 abe      engy        13712 Jul 18 11:34 hello_c
> > -rwxr-xr-x    1 abe      engy       299900 Jul 18 11:33 hello_hs
> >
> > Why is the binary made by ghc 20 times bigger than the one made by gcc?
>
> I don't know for certain, but I've got a couple of guesses:
>
> 1. hello_hs is probably statically linked.  hello_c is probably
>    dynamically linked.
>

Right. The ldd command gives the dependencies (on Linux):

awo@asterix:~> ldd hello
        libc.so.6 => /lib/libc.so.6 (0x40022000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

If you compile hello.c as static binary, like 

	gcc -static -o hello hello.c

then the resulting exe is rather big, too ;-)

awo@asterix:~> ls -l hello
-rwxr-xr-x    1 awo      users     1486299 Jul 18 21:40 hello

So ghc isnt so bad, really :-)

Greetings
Andreas