Hello,
I'm having trouble loading libraries using CFFI 0.9.0 on debian. Example:
The test script:
(defpackage #:test (:use #:common-lisp #:cffi))
(in-package #:test)
(defun load-library () (define-foreign-library libc (t (:default "libc"))) (use-foreign-library libc) (format t "libc loaded~%"))
(load-library)
Gives: Unable to load foreign library: libc.so [Condition of type LOAD-FOREIGN-LIBRARY-ERROR]
Restarts: 0: [RETRY] Try loading the foreign library again. 1: [USE-VALUE] Use another library instead. 2: [ABORT-REQUEST] Abort handling SLIME request. 3: [TERMINATE-THREAD] Terminate this thread (#<THREAD "repl-thread" {B1BED31}>)
Backtrace: 0: (CFFI::HANDLE-LOAD-FOREIGN-LIBRARY-ERROR "libc.so" "Unable to load foreign library: ~A" "libc.so") 1: (LOAD-FOREIGN-LIBRARY LIBC) 2: (LOAD-LIBRARY) 3: (SB-INT:EVAL-IN-LEXENV (LOAD-LIBRARY) #<NULL-LEXENV>) 4: (SWANK::EVAL-REGION "(load-library) " T) 5: ((LAMBDA NIL)) 6: ((SB-PCL::FAST-METHOD SWANK-BACKEND:CALL-WITH-SYNTAX-HOOKS (T)) #<unused argument> #<unused argument> #<CLOSURE (LAMBDA NIL) {B75B0C5}>) 7: (SWANK::CALL-WITH-BUFFER-SYNTAX #<CLOSURE (LAMBDA NIL) {B75B0C5}>) 8: (SB-INT:EVAL-IN-LEXENV (SWANK:LISTENER-EVAL "(load-library) ") #<NULL-LEXENV>) 9: ((LAMBDA NIL)) 10: ((SB-PCL::FAST-METHOD SWANK-BACKEND:CALL-WITH-DEBUGGER-HOOK (T T)) #<unused argument> #<unused argument> #<FUNCTION SWANK:SWANK-DEBUGGER-HOOK> #<CLOSURE (LAMBDA NIL) {B75AA35}>) 11: ((LAMBDA NIL)) 12: ((SB-PCL::FAST-METHOD SWANK-BACKEND:CALL-WITH-DEBUGGER-HOOK (T T)) #<unused argument> #<unused argument> #<FUNCTION SWANK:SWANK-DEBUGGER-HOOK> #<FUNCTION (LAMBDA NIL) {A9F13C5}>) 13: (SWANK::CALL-WITH-REDIRECTED-IO #<SWANK::CONNECTION {B01AC89}> #<CLOSURE (LAMBDA NIL) {B75A8E5}>) 14: (SWANK::CALL-WITH-CONNECTION #<SWANK::CONNECTION {B01AC89}> #<FUNCTION (LAMBDA NIL) {A9F13C5}>) 15: (SWANK::HANDLE-REQUEST #<SWANK::CONNECTION {B01AC89}>) 16: ((LAMBDA NIL)) 17: ((LAMBDA NIL)) 18: ((SB-PCL::FAST-METHOD SWANK-BACKEND:CALL-WITH-DEBUGGER-HOOK (T T)) #<unused argument> #<unused argument> #<FUNCTION SWANK:SWANK-DEBUGGER-HOOK> #<CLOSURE (LAMBDA NIL) {B1DA0B5}>) 19: (SWANK::CALL-WITH-REDIRECTED-IO #<SWANK::CONNECTION {B01AC89}> #<CLOSURE (LAMBDA NIL) {B1DA0C5}>) 20: (SWANK::CALL-WITH-CONNECTION #<SWANK::CONNECTION {B01AC89}> #<CLOSURE (LAMBDA NIL) {B1DA0B5}>) 21: (SWANK::CALL-WITH-BINDINGS NIL #<CLOSURE (LAMBDA NIL) {B1DA095}>) 22: ((LAMBDA NIL)) 23: ("foreign function: call_into_lisp") 24: ("foreign function: funcall0") 25: ("foreign function: new_thread_trampoline") 26: ("foreign function: #xB7FCECED")
It is hard to imagine that it can't find the library so I'd guess it is some problem with the loader? dlopen? I'm using SBCL 0.9.11 & debian 2.6.15-1-686 #2 Mon Mar 6 15:27:08 UTC 2006 i686 GNU/Linux
Suggestions?
Thanks, -Hazen
hbabcockos1@mac.com writes:
I'm having trouble loading libraries using CFFI 0.9.0 on debian. Example:
The test script:
(defpackage #:test (:use #:common-lisp #:cffi))
(in-package #:test)
(defun load-library () (define-foreign-library libc (t (:default "libc"))) (use-foreign-library libc) (format t "libc loaded~%"))
(load-library)
Gives: Unable to load foreign library: libc.so [Condition of type LOAD-FOREIGN-LIBRARY-ERROR]
Taking a guess here, but I'd bet that your /usr/lib/libc.so is actually a linker script. I'm not sure what dlopen is defined to do in this case, but you are probably better off loading "libc.so.6" instead (although in practice I doubt you would ever need to really do this since the Lisp implementation is likely to have already loaded libc to begin with..)
James
On Monday, April 24, 2006, at 04:50PM, James Bielman jamesjb@jamesjb.com wrote:
hbabcockos1@mac.com writes:
I'm having trouble loading libraries using CFFI 0.9.0 on debian. Example:
Gives: Unable to load foreign library: libc.so [Condition of type LOAD-FOREIGN-LIBRARY-ERROR]
Taking a guess here, but I'd bet that your /usr/lib/libc.so is actually a linker script. I'm not sure what dlopen is defined to do in this case, but you are probably better off loading "libc.so.6"
Thanks! That was the problem. I was also having trouble loading another library, located in /usr/local/lib. That doesn't seem to be in the default library search path on my debian box, though it is on my OS-X box. Or at least that is my guess based on this working (in the context of define-foreign-library):
(:unix "/usr/local/lib/libplplotd.so")
and this not working:
(:unix "libplplot")
However, maybe I didn't set something up correctly? For SBCL, does CFFI use sb-alien:load-shared-object to load the library?
best, -Hazen
hbabcockos1@mac.com writes:
(:unix "/usr/local/lib/libplplotd.so")
and this not working:
(:unix "libplplot")
Try (:unix "libplplot.so") instead, perhaps.
BTW, you can use load-foreign-library instead of define-foreign-library/use-foreign-library since it's more convenient when experimenting with this kind of stuff.
For SBCL, does CFFI use sb-alien:load-shared-object to load the library?
Yes.