[Pyrex] How to use C functions in many Pyrex files?
Tomasz Primke
tprimke at interia.pl
Wed Apr 5 21:04:38 CEST 2006
> If you want to have the literal equivalent of a C include, you can use:
>
> include "p1.pyx"
>
> Wherever you want to use that function.
I'm not sure, what do you mean by "literal equivalent", so I'll try to
describe what I want to achieve.
I have a Pyrex module, called p1 (p1.pyx). I can "compile" it with pyrexc,
so I'll get p1.c file. The file is then used to make a Python extension
module, with my setup.py file - so I get the p1.so file (I work on a
GNU/Linux box).
Now: I have also other Pyrex modules, called p2 (p2.pyx), p3 (p3.pyx), and
so on. I want to use that C_function function, defined in the p1 module, in
my p2.pyx, p3.pyx (and so on) files (modules). In general: p2, p3 modules
should use some functions from the p1 module. Or in another words: I need
my modules to *share* some C (Pyrex) functions.
I have already tried:
--- p1.pyx file ---
cdef public void C_function( int i ):
print "i =", i
--- p2.pyx file ---
#include "p1.pxi"
def Cfun( int ):
C_function( i )
And I was able to compile it and make Python modules (p1.so and p2.so), but
when I did:
>>> import p2
I got some message about unresolved symbols or something... In general -
Python wasn't able to find out, that the p1.so shared library should be
also loaded (because it has the needed functionality).
I realize, that I could do just:
#include "p1.pyx"
but wouldn't it cause code duplication in p2.so file? In the real life my
modules will be much more complicated, so the code duplication is not a
good idea...
Best regards,
Tomek
More information about the Pyrex
mailing list