stackoverflowwww stackoverflowwww - 3 months ago 5x
Python Question

Python cffi module: does verify() require re-compiling the entire c library I want to use from my python code?

Say I need to use a few functions from a shared library, e. g., from python code. I figured the cffi module could help me, especially as it seems to support opaque types if one uses the


I did not fully understand though, what the documentation means by

verify() [...] is an alternative: instead of doing a dlopen, it generates and compiles a piece of C code.

Do I have to recompile the entire Or just a certain part (relevant parts of the header)? If the latter is the case, is this significantly less of a hassle in terms of dependencies, configuration options, ... ?


No, ffi.verify() (as well as ffi.set_source() in the soon-to-be-released cffi 1.0) generates and compiles a lightweight C wrapper which calls your existing library. The C wrapper contains regular C code that calls the library functions, so as usual with C, the library doesn't need to be recompiled in order to be used---but, also as usual with C, you need to have the headers of that library installed (typically from a package called something like libfoo-dev from your OS distribution).