将 Common Lisp 编译为可执行文件

问题描述 投票:0回答:4

我最近开始使用 SBCL 学习 Common Lisp。如何将 Lisp 程序编译为 Windows 二进制文件?

build common-lisp sbcl
4个回答
39
投票

制作hello.exe:

* (defun main () (print "hello"))

MAIN
* (sb-ext:save-lisp-and-die "hello.exe" :toplevel #'main :executable t)
[undoing binding stack and other enclosing state... done]
[saving current Lisp image into hello.exe:
writing 3160 bytes from the read-only space at 0x22000000
writing 2592 bytes from the static space at 0x22100000
writing 30134272 bytes from the dynamic space at 0x22300000
done]
> dir hello.exe
31,457,304 hello.exe
> hello.exe

"hello"

31 MB 可执行文件!


使用 ASDF 的 UIOP:

https://quickref.common-lisp.net/uiop.html#index-dump_002dimage

这也适用于其他 Lisp,包括 SBCL:

* (require "asdf")
("ASDF" "asdf" "UIOP" "uiop")
* (defun main () (print "hello"))
MAIN
* (setq uiop:*image-entry-point* #'main)
#<FUNCTION MAIN>
* (uiop:dump-image "hello.exe" :executable t)
[undoing binding stack and other enclosing state... done]
[performing final GC... done]
[defragmenting immobile space... (inst,fdefn,code,sym)=828+16731+18346+26762... done]
[saving current Lisp image into hello.exe:
writing 1936 bytes from the static space at 0000000020020000
writing 18743296 bytes from the dynamic space at 0000001000000000
writing 6786336 bytes from the read-only space at 0000000fff980000
writing 1937408 bytes from the fixedobj space at 0000000020120000
writing 11816960 bytes from the text space at 0000000021a20000
done]

> dir hello.exe
41,817,704 hello.exe

16
投票

使用

SB-EXT:SAVE-LISP-AND-DIE
。有关详细信息,请参阅 http://www.sbcl.org/manual/#Saving-a-Core-Image


11
投票
(defun main ()
    (format t "Hello, world!~%"))

(sb-ext:save-lisp-and-die "hello-world.exe"
:executable t
:toplevel 'main)

9
投票

有几种工具可以做到这一点。您可以从Buildapp开始。

© www.soinside.com 2019 - 2024. All rights reserved.