Mathias no longer works for Örebro University. These pages are kept for archive purposes only.

CMU/CL notes


This is some misc. notes about using the lisp system cmucl on linux, for doing socket programming, interfacing to C and writing graphical interfaces (gui) using gtk.

Linking to other programming languages

One way of interfacing your CMU/CL programs to other programming languages is to use the foreign function calls of cmucl. You can do eg:

(ext:load-foreign '("foo.o" "boo.o") -libraries '("-lc" "-lm"))
(import '(c-call:int c-call:void c-call:float c-call:double))
(alien:def-alien-routine
 ("vision_connect" rvision-connect0) int
 (str (* char) :in)
 (port int :in))
(defmacro rvision-connect (str port)
  `(system:without-gcing (rvision-connect0 (system:vector-sap ,str) ,port)))

Where foo.o and boo.o are the result of compiling (but not linking) two C-files that depend on the libraries "-lc" and "-lm". The function alien:def-alien-routine defines a lisp function "rvision-connect0" which can be used to call the C-function "vision_connect" which returns an int and takes two arguments. Since one of the arguments is a C string I also made a simple wrapper macro to cast a lisp string into a c-string before calling the C-function, this is the rvision-connect macro in the end.

If you need to make cmucl load every foreign function in a whole archive / library as opposed to only those library functions referenced by an object file you can use:

(ext:load-foreign "foo.o" -libraries '("--whole-archive" "-lvclient" "--no-whole-archive" "-lm" "-lc"))

Last modified 03/13/12