[Ecls-list] SIMPLE-ERROR: In interpreted code, attempted to call a foreign function but ECL was build without support for that.

Juan Jose Garcia-Ripoll juanjose.garciaripoll at gmail.com
Tue May 21 09:13:50 UTC 2013


On Mon, May 20, 2013 at 4:15 AM, Dietrich Bollmann
<dietrich at formgames.org>wrote:

>
> I tried to do so - but for some reason I never get it work...
>

The CFFI model is simply too rigid: they assume that libraries can be
loaded at run time, always. Instead ECL supports also a model in which
libraries are linked with the compiled code, being available that way. I
fear there is no way to work around this but using ECL's own FFI mingled
with CFFI

> (ql:quickload :cffi)
To load "cffi":
  Load 1 ASDF system:
    cffi
; Loading "cffi"

(:CFFI)
> (compile-file "foo.lsp" :load t)

;;;
;;; Compiling foo.lsp.
;;; OPTIMIZE levels: Safety=2, Space=0, Speed=3, Debug=0
;;;
;;; Compiling (DEFCFUN (MYCOS "cos") ...).
;;; End of Pass 1.
;;; Emitting code for MYCOS.
;;; Finished compiling foo.lsp.
;;;
;;; Loading "/Users/jjgarcia/foo.fas"
C:    cos(3.2000000000000001777d+0) = -0.9982947757947531
Lisp: cos(3.2000000000000001777d+0) = -0.9982947757947531
#P"/Users/jjgarcia/foo.fas"
NIL
NIL


----

;;; Nothing special about the "CFFI-USER" package.  We're just
;;; using it as a substitute for your own CL package.
(defpackage :cffi-user
  (:use :common-lisp :cffi))

(in-package :cffi-user)

#-ecl
(progn
  (define-foreign-library libm
      (:unix (:or "libm.so" "libm.dylib"))
    (t (:default "libm")))
  (use-foreign-library libm))

#+ecl
(ffi:load-foreign-library "/usr/lib/libm.dylib" :system-library nil)

;;; Initialize libcurl with FLAGS.
(defcfun (mycos "cos") :double (value :double))

(format t "C:    cos(~e) = ~g~%" 3.2d0 (mycos 3.2d0))
(format t "Lisp: cos(~e) = ~g~%" 3.2d0 (cos 3.2d0))



-- 
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/20130521/f2cc878b/attachment.html>


More information about the ecl-devel mailing list