[Ecls-list] build-shared-library and export functions

Juan Jose Garcia-Ripoll jjgarcia at users.sourceforge.net
Sun Sep 9 08:34:53 UTC 2007


This is probably what you are looking for:

test_l.lisp

(defpackage "TEST"
(:use "COMMON-LISP")
(:nicknames "TEST")
(:export "GET-MSG-TEXT"))

(in-package test)

(declaim (si::c-export-fname get-msg-text))

(defun get-msg-text()
  (print "Hello world!")
  (values "Hello from ECL!"))

foo.c:

#include <ecl/ecl.h>

extern void init_LIBTEST(cl_object flag);

extern cl_object test_get_msg_text(int narg, ...);

int main(int argc, char **argv)
{
  cl_object result;
  cl_boot(argc,argv);

  read_VV(OBJNULL, init_LIBTEST);

  result=test_get_msg_text(0);

}

$ ecl
(require 'cmp)
(compile-file "test_l.lisp" :system-p t :c-file t)
(c:build-shared-library "test" :lisp-files '("test_l.o"))
(quit)
$ gcc -g -I$HOME/include -L$HOME/lib -L./ -o foo.exe foo.c -ltest -lec
$ ./foo.exe

"Hello world!"

-- 
Facultad de Fisicas, Universidad Complutense,
Ciudad Universitaria s/n Madrid 28040 (Spain)
http://juanjose.garciaripoll.googlepages.com




More information about the ecl-devel mailing list