2

I did write a small program using Haskell in Windows. The program depends only on base, diagrams-lib and diagrams-rasterific. The generated standalone executable is huge (25633 KB).

I have read several similar questions (Small Haskell program compiled with GHC into huge binary), but all of them presume Linux is being used. I think that the problem is that everything used (or not) is statically linked into the executable. This includes (I guess) the libraries that in Linux are taken as granted and in Windows are not available.

Any help for reducing the size of the executable will be welcome.

OS: Windows 7 64 bits Pro, Haskell Stack: lts-8.16

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
Román García
  • 425
  • 1
  • 4
  • 16
  • 4
    `diagrams` isn't exactly a small dependency, because it incurs a lot of Edward Kmett's huge tool chain, as it uses the [`linear` library](http://hackage.haskell.org/package/linear) for its vector spaces and the full [`lens` framework](http://hackage.haskell.org/package/lens). Frankly, I think it would be good to trim those dependencies down a bit again... but then, for most people, a 25 MB executable is nothing to worry about at all. – leftaroundabout Jun 22 '17 at 19:58
  • 1
    [Here's](https://stackoverflow.com/a/18636018/15467) a "Hello, world" program that, on Windows, gets down to 13K. – ja. Jun 22 '17 at 22:40
  • 1
    What size were you expecting for your program and why? – jberryman Jun 22 '17 at 22:46
  • @ja can you elaborate? Using -O2 option makes the executable just a bit bigger (25671KB) and strip is a *nix tool that I can't find in Windows. – Román García Jun 23 '17 at 03:30
  • @leftaroundabout I was convinced it was a Windows issue but I removed the `diagrams` dependency, and now the executable is only 1414KB. Please post your comment as answer to accept it. – Román García Jun 23 '17 at 04:24
  • 1
    You can compress with [UPX](https://upx.github.io/). It works very well on Windows & Linux. I often use it and the size of the compressed executable is usually about 18% the one of the original file. – Stéphane Laurent Jun 23 '17 at 16:58
  • Wow, I've just tried UPX, and I am amazed so far. Got an executable of mine from 26MB to 5.6MB. Thanks a lot for recommending it @StéphaneLaurent, I didn't know about it before. – Wizek Jun 24 '17 at 08:43

0 Answers0