3.3  An example

To compile a Scheme program (assuming a UNIX-like environment) we perform the following steps:

If multiple bodies of Scheme code are to be combined into a single executable, then we have to compile each file and link the resulting object files together with the runtime system:

The declarations specify which of the compiled files is the main module, and which is the library module. An executable can only have one main module, since a program has only a single entry-point. In this case foo.scm is the main module, because it doesn't have a unit declaration.

Extensions to the basic CHICKEN runtime libraries are available in a separate utility library (libsrfi-chicken.[a|so] and libstuffed-chicken.[a|so] on UNIX-like platforms, libsrfi-chicken.lib and libstuffed-chicken.lib on Windows systems). Whenever you use one or more of the units extras, format, srfi-1, srfi-4, srfi-13, srfi-14, srfi-18, srfi-25, srfi-37, posix, script-utils, lolevel, tinyclos or regex, then you should add these library to the command line of the C compiler or linker (this is equivalent to adding the -extra-libs option to chicken-config):

  ;;; foo.scm

  (declare (uses posix format))

  (format #t "Anno Domini ~@R~%" 
        (+ 1900 (vector-ref (seconds->local-time (current-seconds)) 5))

  % chicken foo.scm
  % gcc foo.c `chicken-config -cflags -extra-libs -libs` -o foo
  % foo