From: pocket on
Hello.
I want to use share library in /usr/local/lib with cffi on my MacOSX
10.6 with SBCL SBCL 1.0.30
But, when I try to use share library in /usr/local/lib like this:

(define-foreign-library libqrencode
(:darwin "libqrencode.dylib")
(t (:default "libqrencode")))

(use-foreign-library libqrencode)

But, I got error:

debugger invoked on a LOAD-FOREIGN-LIBRARY-ERROR:
Unable to load foreign library (LIBQRENCODE).
Error opening shared object "libqrencode.dylib":
dlopen(3) failed.

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
0: [RETRY ] Try loading the foreign library again.
1: [USE-VALUE] Use another library instead.
2: [ABORT ] Exit debugger, returning to top level.

(CFFI::FL-ERROR "Unable to load foreign library (~A).~% ~A")
[:EXTERNAL]

Then I try to use another library in /usr/local/lib/. But I got same
error.

So I try to read some existing asdf-library may be using library in /
usr/local/lib.
I choose cl-png this asdf-library working fine on my system and I have
libpng12.dylib in /usr/local/lib
Then I found define-foreign-library in cl-png like this:

(define-foreign-library libpng
;; (:unix (:or "libpng12.0.dylib" "libpng12.dylib" "libpng12.so.0"))
(t (:default "libpng12")))

So I try to same definition to libqrencode like this:

(define-foreign-library libqrencode
;; (:unix (:or "libpng12.0.dylib" "libpng12.dylib" "libpng12.so.0"))
(t (:default "libqrencode")))

But, I still get same error. I search about it but I can't get any
help.
What is different betwwn libpng12.dylib and libqrencode.dylib.

Some Info:
$locate libqrencode
/usr/local/lib/libqrencode.3.dylib
/usr/local/lib/libqrencode.dylib
/usr/local/lib/libqrencode.la
/usr/local/lib/pkgconfig/libqrencode.pc

$locate libpng12
/Applications/Gimp.app/Contents/Resources/lib/libpng12.0.dylib
/Applications/Gimp.app/Contents/Resources/lib/libpng12.dylib
/Applications/Inkscape.app/Contents/Resources/lib/libpng12.0.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/X11/include/libpng12
/Developer/SDKs/MacOSX10.5.sdk/usr/X11/include/libpng12/png.h
/Developer/SDKs/MacOSX10.5.sdk/usr/X11/include/libpng12/pngconf.h
/Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib/libpng12.0.0.0.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib/libpng12.0.26.0.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib/libpng12.0.35.0.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib/libpng12.0.dylib
/Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib/libpng12.dylib
/Developer/SDKs/MacOSX10.6.sdk/usr/X11/include/libpng12
/Developer/SDKs/MacOSX10.6.sdk/usr/X11/include/libpng12/png.h
/Developer/SDKs/MacOSX10.6.sdk/usr/X11/include/libpng12/pngconf.h
/Developer/SDKs/MacOSX10.6.sdk/usr/X11/lib/libpng12.0.35.0.dylib
/Developer/SDKs/MacOSX10.6.sdk/usr/X11/lib/libpng12.0.dylib
/Developer/SDKs/MacOSX10.6.sdk/usr/X11/lib/libpng12.dylib
/Library/Frameworks/Cairo.framework/Libraries/libpng12.0.dylib
/Library/Frameworks/Gtk.framework/Libraries/libpng12.0.dylib
/usr/X11/bin/libpng12-config
/usr/X11/include/libpng12
/usr/X11/include/libpng12/png.h
/usr/X11/include/libpng12/pngconf.h
/usr/X11/lib/libpng12.0.35.0.dylib
/usr/X11/lib/libpng12.0.dylib
/usr/X11/lib/libpng12.dylib
/usr/X11/lib/pkgconfig/libpng12.pc
/usr/local/bin/libpng12-config
/usr/local/include/libpng12
/usr/local/include/libpng12/png.h
/usr/local/include/libpng12/pngconf.h
/usr/local/lib/libpng12.0.dylib
/usr/local/lib/libpng12.a
/usr/local/lib/libpng12.dylib
/usr/local/lib/libpng12.la
/usr/local/lib/pkgconfig/libpng12.pc

From: Tamas K Papp on
On Wed, 06 Jan 2010 06:48:16 -0800, pocket wrote:

> Hello.
> I want to use share library in /usr/local/lib with cffi on my MacOSX
> 10.6 with SBCL SBCL 1.0.30
> But, when I try to use share library in /usr/local/lib like this:
>
> (define-foreign-library libqrencode
> (:darwin "libqrencode.dylib")
> (t (:default "libqrencode")))
>
> (use-foreign-library libqrencode)
>
> But, I got error:
>
> debugger invoked on a LOAD-FOREIGN-LIBRARY-ERROR:
> Unable to load foreign library (LIBQRENCODE). Error opening shared
> object "libqrencode.dylib": dlopen(3) failed.

Check *foreign-library-directories*. See
http://common-lisp.net/project/cffi/manual/html_node/_002aforeign_002dlibrary_002ddirectories_002a.html

Note that the OS should set this up properly, but sometimes it doesn't
work on Darwin. Then try

#+darwin (pushnew "/usr/local/lib/" *foreign-library-directories*)

HTH,

Tamas
From: Francogrex on
On Jan 6, 3:48 pm, pocket <poketo7...(a)yahoo.co.jp> wrote:
> Hello.
> I want to use share library in /usr/local/lib with cffi on my MacOSX
> 10.6 with SBCL SBCL 1.0.30
> But, when I try to use share library in /usr/local/lib like this:

What happens when you directly use (cffi:load-foreign-library "/usr/
local/lib/yourlib.so") ?
From: pocket on
On 1月7日, 午前12:46, Francogrex <fra...(a)grex.org> wrote:
> On Jan 6, 3:48 pm, pocket <poketo7...(a)yahoo.co.jp> wrote:
>
> > Hello.
> > I want to use share library in /usr/local/lib with cffi on my MacOSX
> > 10.6 with SBCL SBCL 1.0.30
> > But, when I try to use share library in /usr/local/lib like this:
>
> What happens when you directly use (cffi:load-foreign-library "/usr/
> local/lib/yourlib.so") ?

When I try to load /usr/local/lib/libqrencode.dylib directly.
I got same error:

* (cffi:load-foreign-library "/usr/local/lib/libqrencode.dylib")

debugger invoked on a CFFI:LOAD-FOREIGN-LIBRARY-ERROR:
Unable to load foreign library (NIL).
Error opening shared object "/usr/local/lib/libqrencode.dylib":
dlopen(3) failed.

Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
0: [RETRY ] Try loading the foreign library again.
1: [USE-VALUE] Use another library instead.
2: [ABORT ] Exit debugger, returning to top level.

(CFFI::FL-ERROR "Unable to load foreign library (~A).~% ~A")
[:EXTERNAL]

Here is my backtrace in sbcl:


0: (CFFI::FL-ERROR "Unable to load foreign library (~A).~% ~A")
[:EXTERNAL]
1: (CFFI::LOAD-FOREIGN-LIBRARY-PATH NIL "/usr/local/lib/
libqrencode.dylib")
2: (CFFI:LOAD-FOREIGN-LIBRARY "/usr/local/lib/libqrencode.dylib")
3: (SB-INT:SIMPLE-EVAL-IN-LEXENV
(CFFI:LOAD-FOREIGN-LIBRARY "/usr/local/lib/libqrencode.dylib")
#<NULL-LEXENV>)
4: (INTERACTIVE-EVAL
(CFFI:LOAD-FOREIGN-LIBRARY "/usr/local/lib/libqrencode.dylib"))
[:EXTERNAL]
5: (SB-IMPL::REPL-FUN NIL)
6: ((LAMBDA ()))
7: (SB-IMPL::%WITH-REBOUND-IO-SYNTAX #<CLOSURE (LAMBDA #) {11885DBD}>)
8: (SB-IMPL::TOPLEVEL-REPL NIL)
9: (SB-IMPL::TOPLEVEL-INIT)
10: ((LABELS SB-IMPL::RESTART-LISP))
From: "Dimiter "malkia" Stanev" on
Is it possible that this library is 64-bit only?

On Mac you can have multiple-architecutures in the same .o, .dylib,
elf file (called FAT, or Universal binaries).

For example:

malkia ~ $ lipo -info /usr/lib/libz.dylib
Architectures in the fat file: /usr/lib/libz.dylib are: x86_64 i386
ppc7400

So make sure that this library is compiled for the right architecutre,
and recompile it if needed.

With MacPorts, usually this is enough:

sudo port install somelib +universal

On Jan 6, 11:14 pm, pocket <poketo7...(a)yahoo.co.jp> wrote:
> On 1月7日, 午前12:46, Francogrex <fra...(a)grex..org> wrote:
>
> > On Jan 6, 3:48 pm, pocket <poketo7...(a)yahoo.co.jp> wrote:
>
> > > Hello.
> > > I want to use share library in /usr/local/lib with cffi on my MacOSX
> > > 10.6 with SBCL SBCL 1.0.30
> > > But, when I try to use share library in /usr/local/lib like this:
>
> > What happens when you directly use (cffi:load-foreign-library "/usr/
> > local/lib/yourlib.so") ?
>
> When I try to load /usr/local/lib/libqrencode.dylib directly.
> I got same error:
>
> * (cffi:load-foreign-library "/usr/local/lib/libqrencode.dylib")
>
> debugger invoked on a CFFI:LOAD-FOREIGN-LIBRARY-ERROR:
>   Unable to load foreign library (NIL).
>   Error opening shared object "/usr/local/lib/libqrencode.dylib":
>   dlopen(3) failed.
>
> Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.
>
> restarts (invokable by number or by possibly-abbreviated name):
>   0: [RETRY    ] Try loading the foreign library again.
>   1: [USE-VALUE] Use another library instead.
>   2: [ABORT    ] Exit debugger, returning to top level.
>
> (CFFI::FL-ERROR "Unable to load foreign library (~A).~%  ~A")
> [:EXTERNAL]
>
> Here is my backtrace in sbcl:
>
> 0: (CFFI::FL-ERROR "Unable to load foreign library (~A).~%  ~A")
> [:EXTERNAL]
> 1: (CFFI::LOAD-FOREIGN-LIBRARY-PATH NIL "/usr/local/lib/
> libqrencode.dylib")
> 2: (CFFI:LOAD-FOREIGN-LIBRARY "/usr/local/lib/libqrencode.dylib")
> 3: (SB-INT:SIMPLE-EVAL-IN-LEXENV
>     (CFFI:LOAD-FOREIGN-LIBRARY "/usr/local/lib/libqrencode.dylib")
>     #<NULL-LEXENV>)
> 4: (INTERACTIVE-EVAL
>     (CFFI:LOAD-FOREIGN-LIBRARY "/usr/local/lib/libqrencode.dylib"))
> [:EXTERNAL]
> 5: (SB-IMPL::REPL-FUN NIL)
> 6: ((LAMBDA ()))
> 7: (SB-IMPL::%WITH-REBOUND-IO-SYNTAX #<CLOSURE (LAMBDA #) {11885DBD}>)
> 8: (SB-IMPL::TOPLEVEL-REPL NIL)
> 9: (SB-IMPL::TOPLEVEL-INIT)
> 10: ((LABELS SB-IMPL::RESTART-LISP))