Shammer's Philosophy

My private adversaria

ClozureCL のコードをコンパイル

compilation - Compiling Binaries with Clozure Common Lisp - Stack Overflowに例がある。Native の実行バイナリにしたいので以下のようにする。

? (load "test.lisp")
#P"/Users/xxx/test.lisp"
? (save-application "test" :toplevel-function #'test :prepend-kernel t)
$

コンパイル対象ファイルはロードしておき、その中で main メソッドになるものを :toplevel-function で指定する。test.lisp の内容は以下。

(defun test ()
  (format t "~A~%" "HelloWorld!")
  0)

最後の 0 は必要なのかよくわからないが、参考にしたサイトでは 0 を入れていたので同じようにしてみた。結果、test というバイナリが生成される。実行すると以下のようになる。

$ ./test
HelloWorld!
$