Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5959351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:40:21+00:00 2026-05-22T18:40:21+00:00

Even trivially small Haskell programs turn into gigantic executables. I’ve written a small program,

  • 0

Even trivially small Haskell programs turn into gigantic executables.

I’ve written a small program, that was compiled (with GHC) to the binary with the size extending 7 MB!

What can cause even a small Haskell program to be compiled to the huge binary?

What, if anything, can I do to reduce this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:40:22+00:00Added an answer on May 22, 2026 at 6:40 pm

    Let’s see what’s going on, try

      $ du -hs A
      13M   A
    
      $ file A
      A: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), 
         dynamically linked (uses shared libs), for GNU/Linux 2.6.27, not stripped
    
      $ ldd A
        linux-vdso.so.1 =>  (0x00007fff1b9ff000)
        libXrandr.so.2 => /usr/lib/libXrandr.so.2 (0x00007fb21f418000)
        libX11.so.6 => /usr/lib/libX11.so.6 (0x00007fb21f0d9000)
        libGLU.so.1 => /usr/lib/libGLU.so.1 (0x00007fb21ee6d000)
        libGL.so.1 => /usr/lib/libGL.so.1 (0x00007fb21ebf4000)
        libgmp.so.10 => /usr/lib/libgmp.so.10 (0x00007fb21e988000)
        libm.so.6 => /lib/libm.so.6 (0x00007fb21e706000)
        ...      
    

    You see from the ldd output that GHC has produced a dynamically linked executable, but only the C libraries are dynamically linked! All the Haskell libraries are copied in verbatim.

    Aside: since this is a graphics-intensive app, I’d definitely compile with ghc -O2

    There’s two things you can do.

    Stripping symbols

    An easy solution: strip the binary:

    $ strip A
    $ du -hs A
    5.8M    A
    

    Strip discards symbols from the object file. They are generally only needed for debugging.

    Dynamically linked Haskell libraries

    More recently, GHC has gained support for dynamic linking of both C and Haskell libraries. Most distros now distribute a version of GHC built to support dynamic linking of Haskell libraries. Shared Haskell libraries may be shared amongst many Haskell programs, without copying them into the executable each time.

    At the time of writing Linux and Windows are supported.

    To allow the Haskell libraries to be dynamically linked, you need to compile them with -dynamic, like so:

     $ ghc -O2 --make -dynamic A.hs
    

    Also, any libraries you want to be shared should be built with --enabled-shared:

     $ cabal install opengl --enable-shared --reinstall     
     $ cabal install glfw   --enable-shared --reinstall
    

    And you’ll end up with a much smaller executable, that has both C and Haskell dependencies dynamically resolved.

    $ ghc -O2 -dynamic A.hs                         
    [1 of 4] Compiling S3DM.V3          ( S3DM/V3.hs, S3DM/V3.o )
    [2 of 4] Compiling S3DM.M3          ( S3DM/M3.hs, S3DM/M3.o )
    [3 of 4] Compiling S3DM.X4          ( S3DM/X4.hs, S3DM/X4.o )
    [4 of 4] Compiling Main             ( A.hs, A.o )
    Linking A...
    

    And, voilà!

    $ du -hs A
    124K    A
    

    which you can strip to make even smaller:

    $ strip A
    $ du -hs A
    84K A
    

    An eensy weensy executable, built up from many dynamically linked C and Haskell pieces:

    $ ldd A
        libHSOpenGL-2.4.0.1-ghc7.0.3.so => ...
        libHSTensor-1.0.0.1-ghc7.0.3.so => ...
        libHSStateVar-1.0.0.0-ghc7.0.3.so =>...
        libHSObjectName-1.0.0.0-ghc7.0.3.so => ...
        libHSGLURaw-1.1.0.0-ghc7.0.3.so => ...
        libHSOpenGLRaw-1.1.0.1-ghc7.0.3.so => ...
        libHSbase-4.3.1.0-ghc7.0.3.so => ...
        libHSinteger-gmp-0.2.0.3-ghc7.0.3.so => ...
        libHSghc-prim-0.2.0.0-ghc7.0.3.so => ...
        libHSrts-ghc7.0.3.so => ...
        libm.so.6 => /lib/libm.so.6 (0x00007ffa4ffd6000)
        librt.so.1 => /lib/librt.so.1 (0x00007ffa4fdce000)
        libdl.so.2 => /lib/libdl.so.2 (0x00007ffa4fbca000)
        libHSffi-ghc7.0.3.so => ...
    

    One final point: even on systems with static linking only, you can use -split-objs, to get one .o file per top level function, which can further reduce the size of statically linked libraries. It needs GHC to be built with -split-objs on, which some systems forget to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Even after all the hotfixes and updates that are supposed to fix this, my
Even before telling my question, will tell you that this is a very vague
No matter what I do sys.exit() is called by unittest, even the most trivial
It should be trivial, and it might even be in the help, but I
Even though I always strive for complete validation these days, I often wonder if
Even though I have a robust and fast computer (Pentium Dual Core 2.0 with
Even when BorderStyle is set to 0, it is possible to force a window
Even a simple Notepad application in C# consumes megabytes of RAM as seen in
Even nowadays I often see underscores in Java variables and methods. An example are
Even on big-time sites such as Google, I sometimes make a request and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.