From: Andy
Subject: How do use shared object?
Date: 
Message-ID: <87myxweijz.fsf@cs.hit.edu.cn>
I have a libxxx.so written in C. And I want to use it in CLISP. What
should I do?

From: Slobodan Blazeski
Subject: Re: How do use shared object?
Date: 
Message-ID: <1184582869.844942.139110@r34g2000hsd.googlegroups.com>
On Jul 16, 12:42 pm, Andy <·········@cs.hit.edu.cn> wrote:
> I have a libxxx.so written in C. And I want to use it in CLISP. What
> should I do?

I don't use clisp nor *nix but I suggest you to use CFFI for all your
interaction with c keeping your code compatible with other lisps :
http://common-lisp.net/project/cffi/  if you sometimes decide to use
another implementation.  Clisp is supported with ver >=2.35 and cffi
documentation is great.
From: Pascal Bourguignon
Subject: Re: How do use shared object?
Date: 
Message-ID: <87hco4oakr.fsf@thalassa.lan.informatimago.com>
Andy <·········@cs.hit.edu.cn> writes:

> I have a libxxx.so written in C. And I want to use it in CLISP. What
> should I do?

You could use CFFI, or clisp specific FFI.

CFFI is a portability layer, so if it can do what you want, you shoud
probably prefer it.



With FFI, you just specify the library where your foreign functions
lie:

(ffi:def-call-out my-fun
   (:name "my_fun")
   (:arguments (arg1 ffi:ulong) (arg2 ffi:ulong))
   (:return-type ffi:int)
   (:library "/usr/local/lib/libmy.so")
   (:language :stdc))

See http://clisp.cons.org/impnotes/dffi.html


For CFFI:  http://www.cliki.net/CFFI

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.
From: D Herring
Subject: Re: How do use shared object?
Date: 
Message-ID: <Se6dnVbHTpP0YgbbnZ2dnUVZ_tKjnZ2d@comcast.com>
Andy wrote:
> I have a libxxx.so written in C. And I want to use it in CLISP. What
> should I do?

CFFI looks something like this

(require 'asdf)
(asdf:operate 'asdf:load-op :cffi)
(cffi:load-foreign-library "/path/to/libxxx.so")

(cffi:defcfun ("open" c-open) :int
   "Open a file to get a C file descriptor"
   (file :pointer)
   (flags :int))

(defun open-fid (filename)
   "Wrap open in a more user-friendly interface."
   (let ((cstr (cffi:foreign-string-alloc filename)))
     (prog1
         (c-open cstr 0)
       (cffi:foreign-string-free cstr))))

(let ((fid (open-fid "/tmp/test.txt")))
   ...)


- Daniel
From: D Herring
Subject: Re: How do use shared object?
Date: 
Message-ID: <C8-dnadhG7xvmwHbnZ2dnUVZ_hzinZ2d@comcast.com>
D Herring wrote:
> (cffi:defcfun ("open" c-open) :int
>   "Open a file to get a C file descriptor"
>   (file :pointer)
>   (flags :int))

should be

(cffi:defcfun ("open" c-open) :int
   (file :pointer)
   (flags :int))

-DH