Creating Executables

Newcomers to Lisp often ask how to "create an executable" from their Lisp program.

cl-launch is a utility to allow Lisp programs to be easily invoked from a UNIX command line. See also ShellScripting. Buildapp is an SBCL-specific utility that does something similar to cl-launch.

Creating stand-alone executables is not as common as in C or similar languages. Lisp development is most often interactive. Functions and class definitions are usually compiled and linked into the Lisp environment as soon as the definitions are written. Variables can be updated and functions can be called immediately from the REPL prompt in the Lisp environment. A "program" in Lisp is launched by calling a function like any other.

When a system is complete enough to deliver, the typical route is to load all of the system's definitions into the Lisp environment, "dump" the compiled definitions into an disk image, identifying a "startup function" that will be called to launch the application.

One form of disk image requires a copy of the particular Lisp implementation to be installed on the recipient's machine. This is no different in principle from a C application requiring platform-specific dynamic libraries to run.

The method to create such an image depends on the implementation:

An alternative approach is to create a disk image that includes not only the system itself, but also the Lisp implementation binary. This image will be typically larger than a C executable, because Lisp implementations usually include a debugger and compiler, as well as the full Lisp runtime library.

The Lispbuilder wiki has a tutorial on this topic.

"Tree-shaking" functionality, in principle, can reduce the size of a Lisp executable by excising the compiler or debugger, but this severely reduces the flexibility of the program; the compiler and debugger are handy to interactively and remotely patch the running system on the recipient's machine. Also, the compiler is used in some implementations at unexpected times, for instance, within the CLOS implementation, making tree-shaking somewhat impractical.


FAQ system programming

This page is linked from: document  

CLiki pages can be edited by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively