我正在寻找通过.asd文件中的选项或其他方式设置项目的惯用方法,以便使用cffi自动加载我所依赖的动态外部库。
以下是我尝试的内容: 在一个名为armadillo.lisp的文件中我有
;;; Load the Armadillo Libraries
(push "/users/mcheema/src/c++/lisp-armadillo/" cffi:*FOREIGN-LIBRARY-DIRECTORIES*)
(cffi:define-foreign-library lisp-armadillo-lib
(t "lisp-armadillo.dylib"))
(cffi:load-foreign-library 'lisp-armadillo-lib)
当我第一次启动粘液时,我会输入
(ql:register-local-projects)
(asdf:load-system :cl-armadillo)
这会引发错误:
CL-USER> (asdf:load-system :cl-armadillo)
;Compiling "/Users/mcheema/src/lisp/cl-armadillo/src/armadillo.lisp"...;
Evaluation aborted on #<CFFI::FOREIGN-LIBRARY-UNDEFINED-ERROR #x3020017A461D>.
如果我然后将上面相同的cffi代码片段剪切并粘贴到我的粘液REPL中,我得到:
CL-USER> (push "/users/mcheema/src/c++/lisp-armadillo/" cffi:*FOREIGN-LIBRARY-DIRECTORIES*)
(cffi:define-foreign-library lisp-armadillo-lib
(t "lisp-armadillo.dylib"))
(cffi:load-foreign-library 'lisp-armadillo-lib)
#<FOREIGN-LIBRARY LISP-ARMADILLO-LIB "lisp-armadillo.dylib">
编辑:回答Dirk的评论。目前,specials.lisp和io.lisp都是空文件,保存一个defpackage,一个表格用于整个项目版本号。
(in-package :cl-user)
(defpackage cl-armadillo-asdf
(:use :cl :asdf))
(in-package :cl-armadillo-asdf)
(defsystem cl-armadillo
:author "Munawar Cheema"
:license "LLGPL"
:version "0.0.1"
:depends-on (:uiop :cffi)
:components (
(module "src"
:components
((:file "armadillo" :depends-on ("io"))
(:file "io" :depends-on ("specials"))
(:file "specials"))))
:description "Create a simple interface to the armadillo library"
:long-description "Create a simple interface to the armadillo library"
; :in-order-to ((test-op (load-op cl-armadillo-test))) ; see fukamachi/cl-project.asd
)
我还将armadillo.lisp包含在失败点中
(in-package :cl-user)
(defpackage cl-armadillo
(:use
#:cl
#:uiop
#:cffi
#:cl-armadillo.specials
#:cl-armadillo.io)
(:nicknames :arm)
(:export matrix-destroy
matref
make-matrix-ones
make-matrix-randu
make-matrix-zeros
make-matrix-eye))
(in-package :cl-armadillo)
;;; Load the Armadillo Libraries
(push "/users/mcheema/src/c++/lisp-armadillo/" cffi:*FOREIGN-LIBRARY-DIRECTORIES*)
(cffi:define-foreign-library lisp-armadillo-lib
(t "lisp-armadillo.dylib"))
(cffi:load-foreign-library 'lisp-armadillo-lib)
答案 0 :(得分:0)
经过一些试验和错误后,我想出了如何确保我的代码每次都使用asdf:load-system。关键是要包装库的定义并以eval-when形式更新cffi:* foreign-library-directories:
(eval-when
(:compile-toplevel :load-toplevel :execute)
(pushnew #P"/users/mcheema/src/c++/lisp-armadillo/" cffi:*FOREIGN-LIBRARY-DIRECTORIES*)
(cffi:define-foreign-library lisp-armadillo-lib
(t "lisp-armadillo.dylib"))
(cffi:load-foreign-library 'lisp-armadillo-lib))
代码编辑以反映评论中的pushnew建议