I recently started learning Common Lisp using SBCL. How can I compile my Lisp programs into a Windows binary?
Asked
Active
Viewed 2.9k times
4 Answers
39
Making 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 executable file!

KIM Taegyoon
- 1,917
- 21
- 18
-
1Thanks, this is a good example of what Anton was talking about. Two questions, how would you create an executable from an existing lisp file and is it possible to get the executable to a smaller size? – James McMahon Jan 26 '14 at 15:45
-
7@JamesMcMahon: smaller sizes are possible with some other CL implementations. For example Clozure CL, CLISP, LispWorks, Allegro CL, MKCL. Really small programs can be created with the commercial 'mocl' compiler (though currently not for windows), which only supports a large subset of Common Lisp and which then does not support runtime code loading, runtime compilation, full runtime evaluation, etc. With mocl you get tiny applications, but which are static - similar to what you would expect from a C compiler. It actually compiles to C code. – Rainer Joswig Nov 25 '14 at 14:03
-
You can just save an executable with no :toplevel , and then use that as your new “sbcl binary” to run scripts (with your dependencies already loaded). Just one big file, and instant startup on all scripts. – HappyFace Oct 09 '21 at 16:41
16
Use SB-EXT:SAVE-LISP-AND-DIE
. See http://www.sbcl.org/manual/#Saving-a-Core-Image for details.

Anton Kovalenko
- 20,999
- 2
- 37
- 69
-
2could you provide more info? This points in the right direction but there is a lot of information to digest there for a Lisp newbie. – James McMahon Aug 05 '13 at 02:44
11
(defun main ()
(format t "Hello, world!~%"))
(sb-ext:save-lisp-and-die "hello-world.exe"
:executable t
:toplevel 'main)

Morten Jensen
- 5,818
- 3
- 43
- 55

zxt
- 111
- 1
- 2