[Pyrex] How to use C functions in many Pyrex files?
Ravi Lanka
ravi_lanka at acusim.com
Wed Apr 5 21:47:10 CEST 2006
I don't know your particular situation, but, Instead of using
C_function(..), can't you use C_fun() in p2 and p3.
i.e.,
In p2.pyx:
import p1
retValue = p1.C_fun( i )
...
Ravi
Tomasz Primke wrote:
>>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
>
>_______________________________________________
>Pyrex mailing list
>Pyrex at lists.copyleft.no
>http://lists.copyleft.no/mailman/listinfo/pyrex
>
>
>
More information about the Pyrex
mailing list