After talking with ignas in #lisp about using this interface for GTK, I came up with a patch to add the following features to DEFINE-FOREIGN-LIBRARY:
- A CFFI feature expression of T can be used to define a default clause.
- If a library name is of the format (:DEFAULT STRING) then LOAD-FOREIGN-LIBRARY will append an OS-specific library suffix (.so, dll, .dylib, etc) to STRING before trying to load it. (We will need to extend this list as we test on more operating systems...) There is no facility for specifying versions with :DEFAULT; if you need to load a specific version, you must give the full library name.
If the library you want to link against is "libfoo.so" on Linux, "libfoo.dylib" on Darwin, and "libfoo.dll" on Windows, then the following should do the right thing:
(define-foreign-library foo (t (:default "libfoo")))
I was reluctant to add any default behavior that tries to interpret the foreign library name and add suffixes if not present. I think explicitly requesting addition of the suffix keeps the design cleaner.
Luís, I put a patch file up if you'd like to look it over:
http://slacknet.com/~jamesjb/suffixes.patch
James