Using Python's Cffi And Excluding System Headers
Solution 1:
This is a somewhat generic answer:
While it is possible to use the gcc -E
approach and manually "trim" the result, it is not the recommended way to use CFFI. Instead, the cdef() code is usually made either incrementally (adding functions as needed) or in bulk from an edited copy of the .h file. The first approach works best when copying from man pages; the second approach is for the case where we want complete access to a single 3rd-party library.
In all cases, it is very likely that you need to edit the .h file anyway: the recommended approach is to use ffi.set_source(), and remove from the cdef() any declarations that are superfluous, replacing them with ...
. For example, the actual .h file may contain the declaration #define FOOBAR 42
, but the value 42 should not be relied upon (e.g. it could change in the future), so the cdef() should rather receive #define FOOBAR ...
.
Post a Comment for "Using Python's Cffi And Excluding System Headers"