[Haskell-beginners] GHC-generated executables size
daniel.is.fischer at web.de
Sat Oct 16 07:23:17 EDT 2010
On Saturday 16 October 2010 12:26:00, . wrote:
> I was playing around with ghc again, and I was wondering what makes
> the executables so large and how I could make them smaller (strip works,
> but is there anything more I can do?)
> More specifically, I am compiling a program that uses the GTK+ bindings,
> HDBC, and some things from Prelude.
> The program simply displays a window, and reads and writes values
> from/into a data base file. Not much, really.
> Anyway, the program size is 20MB without stripping, and 10MB after
> stripping ...
> Any hints?
Two things spring to mind (in addition to the static linking mentioned by
1) If you didn't compile the packages with -split-objs, when you use one
function from a module, the entire object file for the module is linked in.
For packages with many modules or many dependencies, that adds up pretty
If you set
in your ~/.cabal/config, packages installed via cabal-install (the cabal
executable) will be built with -split-objs and only the needed functions
will be linked in (at least if you compile your programmes with
optimisations, I don't know whether -O0 uses split object files or the
(Downside: building the packages takes longer, duh; and you need more disk
space for monolithic+split object files, duh again).
2) If it's not (only) that,
it's probably the same effect as discussed in
Simon (PJ) says:
"Every module has a module-initialisation routine. Apart from initialising
the module, it calls the module-initialisation routine for each imported
module. So if M imports module SpecConstr from package ghc, then the
module-initialisatin routine for M will call the initialisation routine for
SpecConstr. Even though nothing from SpecConstr is ultimately used."
So if you import a module (you don't even need to use anything from it)
which transitively imports a lot of modules, you get a ton of module-
People are thinking about how to handle this best (since it affects the
vector package, on which a lot of other packages depend, it's not
> Thanks and good night for now ..
More information about the Beginners