[Pyrex] How to use C functions in many Pyrex files?
Lenard Lindstrom
len-l at telus.net
Thu Apr 6 23:38:45 CEST 2006
On 5 Apr 2006 at 21:04, Tomasz Primke wrote:
[snip]
>
> 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 )
>
--- p2.pyx file ---
include "p1.pxi"
import p1
def Cfun( int i ):
C_function( i )
Build p1.pyx as a normal pyrex module. p2 is more tricky, as the
linker needs information on p1. This is the setup.py file I used to
build p2 with VC on Window. GCC needs something different.
from distutils.core import setup
from distutils.extension import Extension
from Pyrex.Distutils import build_ext
setup(
name = 'p2',
ext_modules=[
Extension("p2", ["p2.pyx"],
library_dirs=["./build/temp.win32-2.3/Release"],
libraries=["p1"]),
],
cmdclass = {'build_ext': build_ext}
)
And finally:
>>> import p2
>>> p2.Cfun(12)
i = 12
>>>
Lenard Lindstrom
<len-l at telus.net>
More information about the Pyrex
mailing list