[Ecls-list] calling ECL functions defined in an ASDF package from C code

Juan Jose Garcia-Ripoll juanjose.garciaripoll at googlemail.com
Sat Jun 25 21:11:15 UTC 2011

On Sat, Jun 25, 2011 at 8:48 PM, Eric Schulte <schulte.eric at gmail.com>wrote:

> Thank you, such an interface sounds ideal.  Do you have any idea of a
> time scale for such an implementation, e.g., on the order of days weeks
> or months?

I just finished the following patch:

 - When building shared and statically linked libraries, ECL creates an
   extra function that performs two tasks: initializing ECL if it wasn't
   before, and initializing the library. This can be used to create
   libraries to be linked with other programs. The name of the function
   begins with main_dll or main_lib but it is output by ECL on screen.

An example is shown below. It has been uploaded to CVS/git but it might not
be functioning perfectly because of other issues -- namely the thing with
compiled data mentioned on a separate thread, which is still under testing.

Feel free to report problems. Best,


$ ecl -norc
ECL (Embeddable Common-Lisp) 11.1.1
Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya
Copyright (C) 1993 Giuseppe Attardi
Copyright (C) 2000 Juan J. Garcia-Ripoll
ECL is free software, and you are welcome to redistribute it
under certain conditions; see file 'Copyright' for details.
Type :h for Help.
Top level.
> (si::system "cat foo.lsp")
(defun foo (x)
 (print x))

> (defparameter *object* (compile-file "foo" :system-p t :verbose nil))

;;; Loading #P"/Users/jjgarcia/lib/ecl-11.1.1/cmp.fas"
;;; Compiling (DEFUN FOO ...).
;;; Emitting code for FOO.
;;; Note:
;;;   Invoking external command:
;;;   gcc -I. -I/Users/jjgarcia/include/ -g -O2 -fPIC -fno-common -Ddarwin
-O2 -w -c foo.c -o foo.o
> (c:build-shared-library "foo" :lisp-files (list *object*))

;;; Note:
;;;   Library initialization function is main_dll_FOO

In this case

main_dll_FOO(int argc, char **argv);

is the initialization routine of the library. Note that this calls cl_boot()
but _you_ should manually insert a call to cl_shutdown() somewhere in your


Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20110625/79e05b9f/attachment.html>

More information about the ecl-devel mailing list