An example on how to embed ECL using C compilers and ASDF.

This commit is contained in:
Juan Jose Garcia Ripoll 2013-05-28 23:07:05 +02:00
parent efec0ee048
commit 83e8057bd1
5 changed files with 39 additions and 0 deletions

13
examples/embed/Makefile Normal file
View file

@ -0,0 +1,13 @@
hello.exe: hello.c hello-lisp.a
$(CC) `ecl-config --cflags` -o $@ hello.c hello-lisp.a \
`ecl-config --ldflags` -lecl
hello-lisp.a: hello-lisp.lisp
ecl -norc \
-eval '(require :asdf)' \
-eval '(push "./" asdf:*central-registry*)' \
-eval '(asdf:make-build :hello-lisp :type :static-library :move-here "./$@")' \
-eval '(quit)'
clean:
-rm -f hello-lisp.a hello.exe

4
examples/embed/README Normal file
View file

@ -0,0 +1,4 @@
This example shows how to compile a Common Lisp program using ECL
and link it together with a C program. The example focuses on the
building process, not on the C code needed to do various things
with the embedded libraries.

View file

@ -0,0 +1,2 @@
(defsystem "hello-lisp"
:components ((:file "hello-lisp")))

View file

@ -0,0 +1 @@
(defun hello-lisp () (format t "hello-lisp!~%"))

19
examples/embed/hello.c Normal file
View file

@ -0,0 +1,19 @@
#include <stdio.h>
#include <ecl/ecl.h>
int main (int argc, char **argv) {
/* Initialize ECL */
cl_boot(argc, argv);
/* Initialize the library we linked in. Each library
* has to be initialized. It is best if all libraries
* are joined using ASDF:MAKE-BUILD.
*/
extern void init_lib_HELLO_LISP(cl_object);
ecl_init_module(NULL, init_lib_HELLO_LISP);
cl_eval(c_string_to_object("(hello-lisp)"));
cl_shutdown();
return 0;
}