Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Common Lisp: standalone executable and shared C library

Until now, I have managed to build my Common Lisp project into a standalone executable with sbcl like this:

(sb-ext:save-lisp-and-die "myexecutable" :toplevel #'main :executable t)

Also, I have made it to call C functions, compiled into a shared library, from common lisp; something like this:

(cffi:define-foreign-library libtest
      (:unix (:default "./libtest"))
      (t (:default "./libtest")))

(cffi:use-foreign-library libtest)

or using an absolute path for the library. The produced executable needs the shared library, libtest.so. I have both myexecutable and libtest.so in the same directory. However, if I use an absolute I cannot distribute those two files. If I use "./libtest" it doesn't find the library when run from another directory.

What is the approach for this case? Thank you in advance!

like image 510
Dimitris Avatar asked Mar 10 '23 23:03

Dimitris


1 Answers

Something like sb-ext:*runtime-pathname* should give you the pathname of the executable.

* (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.

You can then compute a pathname for a file in the same directory:

* (merge-pathnames "libtest" *runtime-pathname*)

#P"/usr/local/bin/libtest"
like image 71
Rainer Joswig Avatar answered Apr 27 '23 23:04

Rainer Joswig