Next: , Previous: , Up: Compiling with Hobbit   [Contents][Index]


2.1 Compiling And Linking

(require 'compile)

Function: hobbit name1.scm name2.scm …

Invokes the HOBBIT compiler to translate Scheme files name1.scm, name2.scm, … to C files name1.c and name1.h.

Function: compile-file name1.scm name2.scm …

Compiles the HOBBIT translation of name1.scm, name2.scm, … to a dynamically linkable object file name1<object-suffix>, where <object-suffix> is the object file suffix for your computer (for instance, .so). name1.scm must be in the current directory; name2.scm, … may be in other directories.

If a file named name1.opt exists, then its options are passed to the build invocation which compiles the c files.

cd ~/scm/
scm -rcompile -e"(compile-file \"example.scm\")"

Starting to read example.scm

Generic (slow) arithmetic assumed: 1.0e-3 found.

** Pass 1 completed **
** Pass 2 completed **
** Pass 3 completed **
** Pass 4 completed **
** Pass 5 completed **
** Pass 6 completed **

C source file example.c is built.
C header file example.h is built.

These top level higher order procedures are not clonable (slow):
(nonkeyword_make-promise map-streams generate-vector runge-kutta-4)
These top level procedures create non-liftable closures (slow):
(nonkeyword_make-promise damped-oscillator map-streams scale-vector elementwise runge-kutta-4 integrate-system)

; Scheme (linux) script created by SLIB/batch Sun Apr  7 22:49:49 2002
; ================ Write file with C defines
(delete-file "scmflags.h")
(call-with-output-file
  "scmflags.h"
  (lambda (fp)
    (for-each
      (lambda (string) (write-line string fp))
      '("#define IMPLINIT \"Init5f4.scm\""
        "#define BIGNUMS"
        "#define FLOATS"
        "#define ARRAYS"
        "#define DLL"))))
; ================ Compile C source files
(system "gcc -O2 -fpic -c -I/usr/local/lib/scm/ example.c")
(system "gcc -shared -o example.so example.o -lm -lc")
(delete-file "example.o")
; ================ Link C object files
(delete-file "slibcat")

Compilation finished at Sun Apr  7 22:49:50
Function: compile->executable exename name1.scm name2.scm …

Compiles and links the HOBBIT translation of name1.scm, name2.scm, … to a SCM executable named exename. name1.scm must be in the current directory; name2.scm, … may be in other directories.

If a file named exename.opt exists, then its options are passed to the build invocation which compiles the c files.

cd ~/scm/
scm -rcompile -e"(compile->executable \"exscm\" \"example.scm\")"

Starting to read example.scm

Generic (slow) arithmetic assumed: 1.0e-3 found.

** Pass 1 completed **
** Pass 2 completed **
** Pass 3 completed **
** Pass 4 completed **
** Pass 5 completed **
** Pass 6 completed **

C source file example.c is built.
C header file example.h is built.

These top level higher order procedures are not clonable (slow):
(nonkeyword_make-promise map-streams generate-vector runge-kutta-4)
These top level procedures create non-liftable closures (slow):
(nonkeyword_make-promise damped-oscillator map-streams scale-vector elementwise runge-kutta-4 integrate-system)

; Scheme (linux) script created by SLIB/batch Sun Apr  7 22:46:31 2002
; ================ Write file with C defines
(delete-file "scmflags.h")
(call-with-output-file
  "scmflags.h"
  (lambda (fp)
    (for-each
      (lambda (string) (write-line string fp))
      '("#define IMPLINIT \"Init5f4.scm\""
        "#define COMPILED_INITS init_example();"
        "#define CCLO"
        "#define FLOATS"))))
; ================ Compile C source files
(system "gcc -O2 -c continue.c scmmain.c findexec.c script.c time.c repl.c scl.c eval.c sys.c subr.c debug.c unif.c rope.c example.c scm.c")
; ================ Link C object files
(system "gcc -rdynamic -o exscm continue.o scmmain.o findexec.o script.o time.o repl.o scl.o eval.o sys.o subr.o debug.o unif.o rope.o example.o scm.o -L/usr/local/lib/scm/ -lm -lc")

Compilation finished at Sun Apr  7 22:46:44

Note Bene:#define CCLO’ must be present in scmfig.h.

In order to see calls to the C compiler and linker, do

(verbose 3)

before calling these functions.


Next: Error Detection, Previous: Compiling with Hobbit, Up: Compiling with Hobbit   [Contents][Index]