24

Given a simple program such as the following, how would you:

  1. compile it as a seperate image file to be loaded by the implementation, and what command line arguments would you use to load it?

  2. Compile it as a standalone binary that can be loaded and run as is.

    Note: I tried adding ":prepend-kernel t" when saving the application only to have the follow error thrown.

    Error: value NIL is not of the
    expected type REAL. While executing: 
    CCL::<-2, in process Initial(0).
    
  3. How would you supress the welcome message?

    The Program

    (defun main ()
      (format t "This is the program.")0)
    

Edit

Hate to answer part of my own question, but I found it none the less.

After the function has been loaded type the following to compile it:

(ccl:save-application "app")

This creates an image file. To load it by passing it to the implementation type (note: the 'ccl' binary is in my system path);

ccl -I app

To run a top level function pass it as a parameter

ccl -I app --eval (main)
Benjamin Pollack
  • 27,594
  • 16
  • 81
  • 105
BlueBadger
  • 898
  • 3
  • 10
  • 20

1 Answers1

32

See the Clozure Common Lisp documentation under Saving Applications

Compiling and Loading Lisp files

You can compile a file named /foo/bar.lisp by calling

 (compile-file "/foo/bar.lisp")

This will create a fasl (FASt Load) file, which contains native code.

You can load the compiled file, the fasl file, with the function LOAD. LOAD and COMPILE-FILE are standard Common Lisp functions.

Creating applications

A few definitions:

  • CCL kernel: the part of CCL which provides low-level runtimes services like memory management.
  • Image: a saved dump of the Lisp heap
  • Application: CCL kernel + image. This can be in one file.

You can save an application by calling a CCL specific function:

(save-application "/foo/bar-image" :toplevel-function #'main)

This will save an image, that you can run using the CCL kernel from a command shell:

ccl -I /foo/bar-image

To save an executable that includes the kernel use this from Lisp:

(save-application "/foo/bar-app"
                  :toplevel-function #'main
                  :prepend-kernel t)

You can call this executable as usual with /foo/bar-app from a command shell.

In Clozure Common Lisp you can check

*command-line-argument-list*

for the list of provided command line arguments.

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
  • Fixed the mistake. Also, the application was created as expected, but when I tried to load the exe an error message told me that the "Program too big to fit in memory". Have you run into this before? Know of a fix? – BlueBadger May 07 '09 at 08:51
  • see my edit, use prepend-kernel to add the kernel to the file – Rainer Joswig May 07 '09 at 08:57
  • I was testing all of this on their Windows Implementation and received the various errors mentioned. I just tested it on a Linux machine and it all works as expected. Thanks. – BlueBadger May 07 '09 at 09:16
  • make sure you have the latest version of CCL on Windows (update from the repository). If that does not work, don't hesitate to report this as a bug on the CCL mailing list or their bugtracker. – Rainer Joswig May 07 '09 at 10:36
  • The "Saving Applications" link at the top is incorrect or out of date. – Faheem Mitha Jul 23 '12 at 06:49
  • @Faheem Mitha: fixed, but it is likely to break again, since the link contains the chapter number - which can change over time. – Rainer Joswig Jul 23 '12 at 08:37