When I read the documentation of DEFINE-FOREIGN-LIBRARY at
https://common-lisp.net/project/cffi/manual/html_node/define_002dforeign_002dlibrary.html#define_002dforeign_002dlibrary
I don't see any way of defining a library and associating a full path.
It really seems (and correct me if I'm wrong) that you can only specify paths in the case "if not found in system-global directories."  But exactly what that means is not immediately clear.  I assume it means that in all cases dload() will be called first, passing the library name, and if that fails, then cffi will attempt to find it elsewhere.

What I'd like to do is circumvent dload() from being called because I know it will load the wrong file (wrong version).

Am I reading the documentation wrong?  Is there really a way to load the dylib from a specified directory and associate it with the lisp symbol for cffi's db?

On Thu, Sep 15, 2016 at 11:24 AM, Jim Newton <jimka.issy@gmail.com> wrote:
The program I'm trying to load has several dependencies which I'm still trying to figure out.
One problem (I think) is that it loading some of its .dylib libraries from the wrong place.
I'd like to load them explicitly to help me debug the problem.
What is the correct way to do this.

Here's what I've tried (but it is not yet correct).
I've added the line to my .sbclrc file.

(cffi:load-foreign-library  "/usr/local/Cellar/cairo/1.12.16_1/lib/libcairo.dylib")

This seems indeed to load the dylib, but later my system calls (CFFI::LOAD-FOREIGN-LIBRARY-PATH :LIBCAIRO "libcairo.dylib" NIL)
which apparently does not realise :LIBCAIRO is already loaded, so it
tries to load cairo again but from /usr/local/Cellar/cairo/1.14.6_1/lib/libcairo.2.dylib

Is there a way for me to tell cffi:load-foreign-library that loading 1.12.16_1 loads :LIBCAIRO ?
I thought about calling cffi:define-foreign-library to associate :LIBCAIRO with the explicit path "/usr/local/Cellar/cairo/1.12.16_1/lib/libcairo.dylib", but I don't see how to do that.

Can someone help?

Thanks.
Jim