Chapter 1. Building programs

1.1. What can ECL do?
1.2. Compiling files
1.3. Building standalone executables
1.4. Building libraries
1.5. File names
1.6. Compiler examples
1.6.1. The hello.lisp file
1.6.2. Example of loadable object file
1.6.3. Example of standalone program
1.6.4. Combining files into a larger FASL

In this section we describe how you can use ECL to build programs and loadable extensions that you can later on distribute to other people.

1.1. What can ECL do?

Some day for some reasons you will be in the need to distribute code that has been developed using ECL. In the following sections we will describe the means that ECL offers you to do so. Basically, these are the alternatives

Source code

You distribute your programs in source code form. This is the easiest and most portable way, but not the fastest one.

Standalone programs

You translate all your lisp code to C using the ECL compiler. The final object files can be linked against other C/C++ libraries to obtain a standalone executable.

You can build statically and dynamically linked libraries.

You translate all your lisp code to C and combine the resulting object files into a single library with .a extension. You can distribute this library to other people and the final users can utilize these libraries to build standalone programs.

You can build dynamically loadable files.

This is the most flexible way. You translate all lisp code to C and link it against possibly other C/C++ libraries to obtain a dynamically loadable library (file type .so under unix). This library can be loaded a startup time to add new functionality to the ECL environment.

In several of these options, we have mentioned the possibility to include C/C++ code. Even if this is possible, you cannot use ordinary C/C++ compilers and makefiles to build ECL extensions, let it be programs or libraries. Briefly, you have to organize your code as follows

  1. Organize the C code as a library, let it be static or dynamic.

  2. Build a function, say mymain(), in which the initialization phase for your library is performed.

  3. Group the code that interfaces to Lisp in separate C files, all of which should include #include <ecl/ecl.h> at the beginning.

  4. Compile your lisp source files.

  5. Let ECL build the final executable or library.

In the final step there are ways to instruct ECL to call your initialization function (mymain() in the example above). These means are explained in the following sections.