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

Juan Jose Garcia-Ripoll juanjose.garciaripoll at googlemail.com
Sun Jun 26 19:20:51 UTC 2011


On Sun, Jun 26, 2011 at 8:49 PM, Eric Schulte <schulte.eric at gmail.com>wrote:

>
> - What are the contents of main.c in your example above?  I assume it is
>  hand written and not generated by ecl?
>
> - Were you required to write a libfoo.h file to include in main.c or is
>  that not necessary?


Sorry, I did not copy-paste the content of the C file. Here it goes:

$ 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.
> (require :cmp)

;;; Loading #P"/Users/jjgarcia/lib/ecl-11.1.1/cmp.fas"
("CMP")

> (setf c::*compile-in-constants* t)

T
> (c:build-shared-library "foo" :lisp-files (list (compile-file "foo"
:system-p t :verbose nil)))
;;; [...]
;;; Note:
;;;   Library initialization function is main_dll_FOO
;;; [...]
#P"libfoo.dylib"
> (ext:system "gcc -o main.exe main.c -L$HOME/lib -L./ -lfoo -lecl")

0
> (ext:system "./main.exe")

HOLA
0
> (ext:system "cat ./foo.lsp")
(defun foo (x)
 (print x))

(foo 'hola)

0
> (ext:system "cat ./main.c")
extern int main_dll_FOO(int argc, char **argv);

int main(int argc, char **argv)
{
  main_dll_FOO(argc, argv);
  si_exit(0);
}

0

Notice that the name of the function was announced by ECL in a comment after
C:BUILD-SHARED-LIBRARY. The declaration does not need to live in a *.h file,
it may be in the same compiled file.

Juanjo

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


More information about the ecl-devel mailing list