Skip to content

Instantly share code, notes, and snippets.

@realark
Created November 20, 2019 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save realark/1b6970a13615a6e389294ab9480d1e09 to your computer and use it in GitHub Desktop.
Save realark/1b6970a13615a6e389294ab9480d1e09 to your computer and use it in GitHub Desktop.
close and re-open foreign libraries on lisp images
(let ((%loaded-libraries% (list)))
(defun %pre-image-save ()
(loop :for library :in (cffi:list-foreign-libraries :loaded-only t) :do
(format T "close foreign lib: ~A~%" library)
(push (cffi:foreign-library-name library) %loaded-libraries%)
(cffi:close-foreign-library library)))
(defun %post-image-load ()
(loop :while %loaded-libraries% :do
(let ((library-name (pop %loaded-libraries%)))
(format T "load foreign lib: ~A~%" library-name)
(cffi:load-foreign-library library-name)))))
(defun make-image ()
(%pre-image-save)
(sb-ext:save-lisp-and-die "my-image-name"
:purify T
:toplevel
#'(lambda ()
(%post-image-load)
(my-main-function))
:executable t
;; :application-type :gui
:save-runtime-options t))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment