Shenal Silva
Shenal Silva

Reputation: 2053

Compiling Common Lisp to an executable

I recently started learning Common Lisp using SBCL. How can I compile my Lisp programs into a Windows binary?

Upvotes: 47

Views: 33667

Answers (4)

Philipp Ludwig
Philipp Ludwig

Reputation: 4192

The correct method is:

(compile-file "file.lisp")

Upvotes: -1

KIM Taegyoon
KIM Taegyoon

Reputation: 2044

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!


Using ASDF's UIOP:

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

This also works in other Lisps, including 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

Upvotes: 43

zxt
zxt

Reputation: 131

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

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

Upvotes: 13

Anton Kovalenko
Anton Kovalenko

Reputation: 21517

Use SB-EXT:SAVE-LISP-AND-DIE. See http://www.sbcl.org/manual/#Saving-a-Core-Image for details.

Upvotes: 15

Related Questions