有没有什么好的方法来制作小型 haskell 可执行文件?使用 ghc6,一个简单的 hello world 程序似乎约为 370kB(剥离之前为 523kB)。C 语言中的 Hello world 大约为 4kB(剥离前为 9kB)。

有帮助吗?

解决方案

通过GHC的开发分支(人确切地知道这是在加入哪个版本?):

$ ghc -o hello hello.hs
$ strip -p --strip-unneeded --remove-section=.comment -o hello-small hello
$ du hello hello-small
700 hello
476 hello-small

添加-dynamic标志动态链接的RTS:

$ ghc -dynamic -o hello hello.hs
$ strip -p --strip-unneeded --remove-section=.comment -o hello-small hello
$ du hello hello-small
24  hello
16  hello-small

参见: http://hackage.haskell.org/trac/ghc /维基/ SharedLibraries / PlatformSupport

有关与C比较:

$ gcc hello.c -o hello
$ strip -p --strip-unneeded --remove-section=.comment -o hello-small hello
$ du hello hello-small
12  hello
8   hello-small

其他提示

GHC静态链接的一切(除了由运行时本身使用的库,其被动态链接)。

在远古时代,GHC链接整个(哈斯克尔)库中,只要你用过从中东西。早前,GHC开始“每个OBJ文件”,这大大减少了二进制大小联系起来。从尺寸来看,您一定发生了使用较新的GHC已经。

在有利的一面,你已经有很多的东西,在那些500K,如多线程核心,垃圾收集等。

至少垃圾收集器再次添加到你的C代码,然后对它们进行比较:)

您所看到的大小是Haskell的运行时(libHSrts.a),这是静态链接到每一个哈斯克尔可执行文件。 如果它是一个共享对象,像librt.o为C,二进制文件是只有几K(在库源拆分的.o文件的大小)。

你的平台上实现libHSrts.a的动态链接短,你可以通过带更小的可执行文件。

如果您的二进制文件的大小真的很重要,你可以使用该工具的 gzexe 是包装用gzip压缩的(最好是已剥离)的可执行文件。在我的64位Linux机器,原来的的Hello World 的程序需要552 KB,剥离393 KB后,并剥离和gzip压缩125 KB之后。 gzip压缩的较暗侧在性能 - 可执行必须被解压缩第一

您应该算你的祝福(370KB Luuuxury):

bash$ sbcl
This is SBCL 1.0.24, an implementation of ANSI Common Lisp.

* (sb-ext:save-lisp-and-die "my.core")
[undoing binding stack and other enclosing state... done]
[saving current Lisp image into ./my.core:
...
done]
bash$ du -sh my.core 
 25M    my.core
bash$ 

虽然严重,而你也许可以摇出哈斯克尔二进制文件位,这真的不是C.公平的比较,有一个更对那里发生的。

我最后一次打GHC(这可能是过时的),它是静态链接的一切,这将是一个因素。

事情正在发生变化——请密切关注 正在进行的工作。

strip -p --strip-unneeded --remove-section=.comment -o your_executable_small your_executable

也尝试寻找LDD -dr your_executable

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top