
Hi Team, I am not sure if I should be asking the question here, however hoping someone could help. we use ffi.cdef for definitions and ffi.dlopen to open shared library. To my understanding ffi.dlopen only works in the presence of a c compiler to dynamically link the shared lib. We have a linux box without gcc in which we are supposed to run this setup. We do have dlopen on the box as man dlopen returns. Could I know if it is at all possible to use ffi.dlopen without a C compiler? Apologies if I am totally off. Thanks, -Roshan

ffi.dlopen does not require a C compiler, ffi.verify does (which we strongly encourage to use). Note that since cffi 1.0 you only require C compiler to create extensions, you can distribute them without a compiler. See documentation for details On Tue, Sep 15, 2015 at 5:39 AM, Roshan Cherian <cherian.rosh@gmail.com> wrote:
Hi Team,
I am not sure if I should be asking the question here, however hoping someone could help.
we use ffi.cdef for definitions and ffi.dlopen to open shared library. To my understanding ffi.dlopen only works in the presence of a c compiler to dynamically link the shared lib. We have a linux box without gcc in which we are supposed to run this setup. We do have dlopen on the box as man dlopen returns. Could I know if it is at all possible to use ffi.dlopen without a C compiler?
Apologies if I am totally off.
Thanks, -Roshan
_______________________________________________ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev

Hi Roshan, On Tue, Sep 15, 2015 at 8:02 AM, Maciej Fijalkowski <fijall@gmail.com> wrote:
ffi.dlopen does not require a C compiler, ffi.verify does (which we strongly encourage to use). Note that since cffi 1.0 you only require C compiler to create extensions, you can distribute them without a compiler. See documentation for details
I added more emphasis about that to the documentation's Overview page. You can see it at https://bitbucket.org/cffi/cffi/wiki/overview (grep for "C compiler"). A bientôt, Armin.

Thanks Armin and Maciej. Thanks for replying, let me share my case I have libical.so built into a path which is set in LD_LIBRARY_PATH. I have upgraded to pypy2.6.1 with libffi3.2.1 and cffi 1.2.1. I have run the following:
export LD_LIBRARY_PATH=./lib ./pypy/bin/pypy>> from cffi import FFI ffi=FFI() ffi.ctypes('''.. ''') ffi.dlopen('ical')
fails with an error not able to load ffi.dlopen('libical.so')
libical=ffi.dlopen('libical.so') <cffi.api.FFILibrary_libical.so <http://cffi.api.ffilibrary_libical.so/> object at 0x00007f4f40f8da60>
import ctypes.util
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
However if I yum install libical and do the above it works just fine, meaning I don't get a AttributeError, so I believe its a problem in loading from LD_LIBRARY_PATH. I did see the following: https://bitbucket.org/cffi/cffi/issues/58/dlopen-ignores-ld_library_path-and..., however I don't understand quite well what the solution was 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. Thanks, -Roshan On Tue, Sep 15, 2015 at 5:23 AM, Armin Rigo <arigo@tunes.org> wrote:
Hi Roshan,
On Tue, Sep 15, 2015 at 8:02 AM, Maciej Fijalkowski <fijall@gmail.com> wrote:
ffi.dlopen does not require a C compiler, ffi.verify does (which we strongly encourage to use). Note that since cffi 1.0 you only require C compiler to create extensions, you can distribute them without a compiler. See documentation for details
I added more emphasis about that to the documentation's Overview page. You can see it at https://bitbucket.org/cffi/cffi/wiki/overview (grep for "C compiler").
A bientôt,
Armin.

Hi Roshan, On Tue, Sep 15, 2015 at 5:01 PM, Roshan Cherian <cherian.rosh@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-o... . 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.
participants (3)
-
Armin Rigo
-
Maciej Fijalkowski
-
Roshan Cherian