mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2025-12-06 02:40:26 -08:00
An example on how to embed ECL using C compilers and ASDF.
This commit is contained in:
parent
efec0ee048
commit
83e8057bd1
5 changed files with 39 additions and 0 deletions
13
examples/embed/Makefile
Normal file
13
examples/embed/Makefile
Normal 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
4
examples/embed/README
Normal 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.
|
||||||
2
examples/embed/hello-lisp.asd
Normal file
2
examples/embed/hello-lisp.asd
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
(defsystem "hello-lisp"
|
||||||
|
:components ((:file "hello-lisp")))
|
||||||
1
examples/embed/hello-lisp.lisp
Normal file
1
examples/embed/hello-lisp.lisp
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
(defun hello-lisp () (format t "hello-lisp!~%"))
|
||||||
19
examples/embed/hello.c
Normal file
19
examples/embed/hello.c
Normal 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;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue