Hi,
I was wondering if define-foreign-library can currently handle libraries that are in the "ar" archive format.
I keep getting an error "Unable to load foreign library". I thought it wasn't looking in the right load path, but I tried specifying the absolute path, directly and with *foreign-libraries-directory*, but that didn't help.
I'm new to lisp so please let me know if this is the wrong forum for this question. I'm running CMUCL on Linux x86.
alexis
On Fri, 2006-01-20 at 05:23 +0000, Alexis Gallagher wrote:
I was wondering if define-foreign-library can currently handle libraries that are in the "ar" archive format.
It is a UNIX limitation, not a Lisp one, that archives cannot be mapped as executable memory. The reasons for this have to do with "position-independent code"; for further information, search that term.
The reason .so libraries were created, in fact, was to offer a dynamically-loadable alternative to archives, which you will find are little more than balls of .o files.
I recommend that you obtain a .so version of your library. For help with this, I suggest contacting the library's maintainer(s).
Stephen Compall wrote:
On Fri, 2006-01-20 at 05:23 +0000, Alexis Gallagher wrote:
I was wondering if define-foreign-library can currently handle libraries that are in the "ar" archive format.
I recommend that you obtain a .so version of your library. For help with this, I suggest contacting the library's maintainer(s).
I found a better solution -- actually, Hans on the #lisp IRC channel handed me a better solution. My library file was "libRNA.a". I wanted access to the function "fold". You can use the ld linker's -u argument to generate a shared object file that includes any symbol and its dependencies. So the following command produced the file libRNA.so file that I needed for CFFI
% ld -u fold -shared -o libRNA.so libRNA.a
CFFI loaded and ran libRNA.so successfully on the first try.
By the way, I also wrapped a C function which returned its string output values through a pointer argument. This is a common requirement, but I know it can be painful if you're using SWIG, a wrapper generator used for python and other dynamic languages, or simply if you're new to bridging languages. The CFFI documentation doesn't given an example of it. Do you or others know, is there a wiki or someplace one could contribute hints and examples for useful but elementary cases like this?
Right now, the libcurl example in the documentation is thorough but for many cases it might be faster and clearer also to have a "cookbook" style set of examples.
cheers, alexis
Alexis Gallagher public@alexisgallagher.com writes:
I was wondering if define-foreign-library can currently handle libraries that are in the "ar" archive format.
No, as far as I know, the ability to load static libraries is unique to CMUCL and Lisp implementations that compile via C.
I keep getting an error "Unable to load foreign library". I thought it wasn't looking in the right load path, but I tried specifying the absolute path, directly and with *foreign-libraries-directory*, but that didn't help.
You will need to load a shared library instead, if possible. Most Lisp FFIs are defined in terms of 'dlopen' or the equivalent.
James