到目前为止,我已经设法使用 sbcl 将我的 Common Lisp 项目构建成一个独立的可执行文件,如下所示:
(sb-ext:save-lisp-and-die "myexecutable" :toplevel #'main :executable t)
另外,我已经使它从 common lisp 调用 C 函数,编译成共享库;像这样:
(cffi:define-foreign-library libtest
(:unix (:default "./libtest"))
(t (:default "./libtest")))
(cffi:use-foreign-library libtest)
或使用库的绝对路径。生成的可执行文件需要共享库 libtest.so。我在同一个目录中有 myexecutable 和 libtest.so。但是,如果我使用绝对文件,则无法分发这两个文件。如果我使用“./libtest”,它在从另一个目录运行时找不到库。
本案的处理方法是什么?
先感谢您!
最佳答案
类似 sb-ext:*runtime-pathname*
应该给你可执行文件的路径名。
* (describe '*runtime-pathname*)
SB-EXT:*RUNTIME-PATHNAME*
[symbol]
*RUNTIME-PATHNAME* names a special variable:
Value: #P"/usr/local/bin/sbcl"
Documentation:
The absolute pathname of the running SBCL runtime.
然后,您可以计算同一目录中文件的路径名:
* (merge-pathnames "libtest" *runtime-pathname*)
#P"/usr/local/bin/libtest"
关于shared-libraries - 通用 Lisp : standalone executable and shared C library,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39884545/