On Mon, May 20, 2013 at 4:15 AM, Dietrich Bollmann <dietrich@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