How to call C function in shared library?
Oleg Krivosheev
kriol at boopsie.fnal.gov
Thu Mar 8 17:18:12 EST 2001
Kalle Svensson <kalle at gnupung.net> writes:
> Sez Oleg Krivosheev:
> > i already have shared library
> > with simple function which takes double
> > and returns double. Is it simple way
> > to call it directly from Python?
>
> You could take a look at SWIG (http://www.swig.org/), or make your own
> wrapper. Something like (extremely untested):
>
> /************ BEGIN **************/
> #include "Python.h"
> #include "myheader.h"
>
> static PyObject *
> wrap_myfunction(PyObject *self, PyObject *args)
> {
> double arg, ret;
> if (!PyArg_ParseTuple(args, "d", &arg))
> return NULL;
> ret = myfunction(arg);
> return Py_BuildValue("d", ret);
> }
>
> /* Module initialisation stuff goes here... */
> /* Check http://www.python.org/doc/current/ext/ */
> /* and http://www.python.org/doc/current/api/ */
> /* for more information... */
> /************ END **************/
>
> > Or some python encapsulation for dlopen/dlsym/dlclose ?
>
> There is the dl module:
> http://www.python.org/doc/current/lib/module-dl.html
umm...
it doesn't support double it seems...
thanks anyway
OK
More information about the Python-list
mailing list