将Common Lisp编译为可执行文件

She*_*lva 32 build sbcl common-lisp

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

KIM*_*oon 28

制作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"
Run Code Online (Sandbox Code Playgroud)

31 MB可执行文件!

  • @JamesMcMahon:其他一些CL实现可以实现更小的尺寸.例如Clozure CL,CLISP,LispWorks,Allegro CL,MKCL.使用商业'mocl'编译器(虽然目前不适用于Windows)可以创建非常小的程序,它只支持Common Lisp的大部分,然后不支持运行时代码加载,运行时编译,完整运行时评估等. mocl你得到很小的应用程序,但它们是静态的 - 类似于你对C编译器的期望.它实际上编译为C代码. (5认同)

Ant*_*nko 12

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

  • 你能提供更多信息吗?这指向正确的方向,但有很多信息要消化Lisp新手. (2认同)

Vse*_*kin 8

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


小智 7

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

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