common lisp调用dll函数例子:
int add(int a,int b){ return a+b; } int sub(int a ,int b){ return a-b; }win下gcc编译生成dll:gcc add.c -shared -o libadd.dll 新建lisp文件test-add.lisp
(asdf:oos 'asdf:load-op :cffi) (defpackage :cffi-user (:use :common-lisp :cffi)) (in-package :cffi-user) (define-foreign-library libadd (:unix (:or "libadd.so")) (:darwin (:or "libadd.dylib")) (:windows (:or "libadd.dll" #p"D:/dev/c/libadd.dll")) (t (:default "libadd"))) (use-foreign-library libadd) (defcfun ("add" c-add) :int (a :int) (b :int)) (defcfun "add" :int (a :int) (b :int)) (defcfun ("sub" c-sub) :int (a :int) (b :int)) (defcfun "sub" :int (a :int) (b :int))然后调用的时候在cl-user输入:
(c-sub 1 2) (sub 10 20) (add 10 (c-sub 100 20))