Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly save Common Lisp image using SBCL?

If I want to create a Lisp-image of my program, how do I do it properly? Are there any prerequisites? And doesn't it play nicely with QUICKLISP?

Right now, if I start SBCL (with just QUICKLISP pre-loaded) and save the image:

(save-lisp-and-die "core")

And then try to start SBCL again with this image

sbcl --core core

And then try to do:

(ql:quickload :cl-yaclyaml)

I get the following:

To load "cl-yaclyaml":
  Load 1 ASDF system:
    cl-yaclyaml
; Loading "cl-yaclyaml"
.......
debugger invoked on a SB-INT:EXTENSION-FAILURE in thread
#<THREAD "main thread" RUNNING {100322C613}>:
  Don't know how to REQUIRE sb-sprof.
See also:
  The SBCL Manual, Variable *MODULE-PROVIDER-FUNCTIONS*
  The SBCL Manual, Function REQUIRE

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
  0: [RETRY                        ] Retry completing load for #<REQUIRE-SYSTEM "sb-sprof">.
  1: [ACCEPT                       ] Continue, treating completing load for #<REQUIRE-SYSTEM "sb-sprof"> as having been successful.
  2:                                 Retry ASDF operation.
  3: [CLEAR-CONFIGURATION-AND-RETRY] Retry ASDF operation after resetting the configuration.
  4: [ABORT                        ] Give up on "cl-yaclyaml"
  5:                                 Exit debugger, returning to top level.

(SB-IMPL::REQUIRE-ERROR "Don't know how to ~S ~A." REQUIRE "sb-sprof")
0] 

Alternatively, if I try:

(require 'sb-sprof)

when sbcl is started with saved core, I get the same error. If sbcl is started just as sbcl there is no error reported.

In fact, pre-loading QUICKLISP is not a problem: the same problem happens if sbcl is called initially with sbcl --no-userinit --no-sysinit.

Am I doing it wrong?

PS. If I use roswell, ros -L sbcl-bin -m core run somehow doesn't pick up the image (tested by declaring variable *A* before saving and not seeing it once restarted).

PS2. So far what it looks like is that sbcl does not provide extension modules (SB-SPROF, SB-POSIX, etc.) unless they are explicitly required prior saving the image.

like image 608
mobiuseng Avatar asked Aug 24 '16 21:08

mobiuseng


2 Answers

Thanks for the help from @jkiiski here is the full explanation and solution:

  1. SBCL uses extra modules (SB-SPROF, SB-POSIX and others) that are not always loaded into the image. These module reside in contrib directory located either where SBCL_HOME environment variable pointing (if it is set) or where the image resides (for example, in /usr/local/lib/sbcl/).

  2. When an image is saved in another location and if SBCL_HOME is not set, SBCL won't be able to find contrib, hence the errors that I saw.

  3. Setting SBCL_HOME to point to contrib location (or copying contrib to image location or new image to contrib location) solves the problem.

  4. Finally, about roswell: roswell parameter -m searches for images in a specific location. For SBCL (sbcl-bin) it would be something like ~/.roswell/impls/x86-64/linux/sbcl-bin/1.3.7/dump/. Secondly, the image name for SBCL must have the form <name>.core. And to start it, use: ros -m <name> -L sbcl-bin run. (Quick edit: better use ros dump for saving images using roswell as it was pointed out to me)

like image 67
mobiuseng Avatar answered Sep 28 '22 03:09

mobiuseng


If you want to create executables, you could try the following:

(sb-ext:save-lisp-and-die 
  "core"
  :compression t
  ;; this is the main function:
  :toplevel (lambda () 
              (print "hell world")                                      
              0)
  :executable t)

With this you should be able to call QUICKLOAD as you wish. Maybe you want to checkout my extension to CL-PROJECT for creating executables: https://github.com/ritschmaster/cl-project

like image 20
Richard Paul Bäck Avatar answered Sep 28 '22 01:09

Richard Paul Bäck