[Pyrex] sharing funcitons with distutils for .pyx

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Sep 20 04:54:43 CEST 2007


Jim Kleckner wrote:
> I have a .pyx file that depends on functions defined in a .c
> file that is included with another .pyx, say it is "cfunc1" defined in 
> cfuncs.c

There's no particularly good way of handling that at
the moment. The current options seem to be:

1) Don't try to link them directly with each other
at the C level. Use cimport and extension types with
C methods, or wrap function pointers in PyCObjects to
pass them from one module to another.

2) Use the trick I posted about in the pyrex list the
other day, where you statically link more than one
module together into one dynamically loaded file, and
put explicit calls into the body of one of the modules
to the init functions of the others, e.g.

# main.pyx
cdef extern void initfoo()
cdef extern void initblarg()

initfoo()
initblarg()

and then in distutils you put all of 'main.pyx',
'foo.pyx' and 'blarg.pyx' into a single Extension
that produces a module called 'main'.

In Python, you then have to import main *before*
attempting to import foo or blarg.

-- 
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | Carpe post meridiem!          	  |
Christchurch, New Zealand	   | (I'm not a morning person.)          |
greg.ewing at canterbury.ac.nz	   +--------------------------------------+



More information about the Pyrex mailing list