So, you decided to play around with quicklisp but when you try to load some packages you get a CFFI:LOAD-FOREIGN-LIBRARY-ERROR ?  CFFI is a Common Lisp library for interfacing with C libraries.  So if you install a quicklisp package like SDL2 it will attempt to load the libSDL2 shared library (libSDL2.dylib on Mac OS X) so that CFFI can forward calls to the shared library.  Usually when this error arises CFFI can’t find the library at all**.  What you need to do is just tell CFFI how to find it.  CFFI has a variable cffi:*foreign-library-directories* which is a list of directories to hunt for dynamic libraries.  So you can do something like this if you library is in “/opt/local/lib”:

You could even throw this code in your init file for you lisp as well so that it always gets executed (sbcl: ~/.sbclrc  ccl:~/.ccl-init.lisp)

** You also might want to check that your architecture is correct for your lisp as well (on Mac OS X “lipo -info <library file>”)


  1. Hi,

    I’ve tried your solution with sbcl installing cl-devil but I get this error
    debugger invoked on a LOAD-FOREIGN-LIBRARY-ERROR in thread
    Unable to load any of the alternatives:
    (“libIL.dylib” “libIL.1.dylib”)

    those files are in /usr/local/lib so I’ve appendend
    (pushnew “/usr/local/lib/”
    :test #’equal)

    to ~/.sbclrc without success

    can you please help me?

    I’m on Osx Yosemite, and have installed DevIL with homebrew, lipo -info gives this result:
    $ lipo -info /usr/local/lib/libIL.dylib
    Non-fat file: /usr/local/lib/libIL.dylib is architecture: x86_64
    have you some suggestions

    1. I’m sorry Francesco, this reply is really late. Are you using the 64 bit version of sbcl? If it still fails try just typing in cffi:*foreign-library-directories* to verify that the path is in there. Sorry again about the delay, maybe this comment will help someone else though.

Leave a Reply

Your email address will not be published. Required fields are marked *