Skip to content

Instantly share code, notes, and snippets.

@spacebat
Created April 8, 2020 23:27
Show Gist options
  • Save spacebat/2a1595991ed9ec7dc6496b6a573433ca to your computer and use it in GitHub Desktop.
Save spacebat/2a1595991ed9ec7dc6496b6a573433ca to your computer and use it in GitHub Desktop.
Create and run a standalone exeutable in ECL
(with-open-file (f "print-args.lisp" :direction :output :if-does-not-exist :create :if-exists :overwrite)
(dolist (expr '((defun print-args ()
(princ (cdr (ext:command-args))))
(print-args)
(quit)))
(prin1 expr f)
(terpri f))
(force-output f))
(defparameter *object-file* (compile-file "print-args.lisp" :system-p t))
(defparameter *executable* (c:build-program "print-args" :lisp-files (list *object-file*)))
(assert (zerop (nth-value 1 (ext:run-program "./print-args" '("4" "5" "6" "7") :output t))))
(terpri)
(ext:run-program "du" '("-h" "print-args") :output t)
(quit)
@spacebat
Copy link
Author

spacebat commented Apr 8, 2020

The output, after startup and compiler noise:

(4 5 6 7)
 12K	print-args

It also pulls in the shared library libecl.16.1.3.dylib on my system which is 2.5MB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment