Hi,
On 14 April 2016 at 20:58, <
ecastro...@gmail.com> wrote:
> I'm trying to distribute a package that includes a compiled library. Most
> project I've seen out there link the CFFI wrapper to some library that's
> already installed on the system, but in my case I need to somehow link to it
> after installing the package or with a relative path.
Note that, at least on Linux and OS/X, it is more messy: a library or
program that depends on another library normally does not contain any
path, and the system will look for that library in the standard paths
(or in LD_LIBRARY_PATH). The fact that the library was in a temporary
location when you compiled doesn't mean that the path to that location
is included in the binary---it is not. You need semi-independently to
make sure that gcc finds the library when compiling, *and* that the
system finds the library when running. For the runtime, there are
ways based on "rpath" to specify the path to the library, but they are
very, very, very much platform-specific (and hackish).
On Windows, at least, you can place a DLL inside the same directory as
the DLL/EXE that uses it, and it will be found.
The only clean solution I can recommend is that if you want to
distribute some library together with its cffi wrapper, you should
arrange to compile everything as a single library, instead of two (the
original library + the Python cffi wrapper library). Then there is no
problem. There are two ways:
* something like ``ffi.set_source(..., ...,
sources=[list-of-C-files])``, if you can convert the original
library's Makefile specificities to extra set_source() arguments
* or, use ``ffi.emit_c_code()`` instead of ``ffi.compile()``, and then
compile the produced C file together with the rest of the library,
e.g. by adding it manually to the library's own Makefile. (Might be a
bit messy because you might also need to set up paths like
libpython's, which would be done for you by ``ffi.compile()``.)
A bientôt,
Armin.