[pypy-dev] cffi dlopen

Armin Rigo arigo at tunes.org
Tue Sep 15 17:17:27 CEST 2015


Hi Roshan,

On Tue, Sep 15, 2015 at 5:01 PM, Roshan Cherian <cherian.rosh at gmail.com> wrote:
>>>>> libical = ffi.dlopen(ctypes.util.find_library('ical'))
>>>>> libical.ical_set_unknown_token_handling_setting(libical.ICAL_ASSUME_IANA_TOKEN)
>
> I get an error: AttributeError: ical_set_unknown_token_handling_setting

This means the library file was found, but it doesn't contain any
symbol of the name "ical_set_unknown_token_handling_setting".  It may
be because such a name is actually a macro.  In that case you can't
use ffi.dlopen().

You should look at ffi.set_source() instead (and *not* ffi.verify();
Maciej probably mentioned this by mistake, it is now called
set_source()).

> I haven't tried out ffi.verify I am not sure how to load a shared lib using
> ffi.verify, I am sorry if my understanding is wrong.

See http://cffi.readthedocs.org/en/latest/overview.html#real-example-api-level-out-of-line
.  In your case you need:

ffi.set_source("_ical_cffi",
    """ #include <ical.h>
    """,
    include_dirs=['./include'],    # or where ical.h is
    libraries=['ical'],
    library_dirs=['./lib'],             # or where libical.so is
)

You also need the same ffi.cdef() as you use now, and ffi.compile() as
shown in the example.  The ffi.cdef() can use the syntax ``...``
(dot-dot-dot) in many places when it is combined with
ffi.set_source().  See the rest of the documentation section for more.


A bientôt,

Armin.


More information about the pypy-dev mailing list