[Pyrex] How to use function defined in C-file?
Tomasz Primke
tprimke at interia.pl
Wed Nov 9 19:37:13 CET 2005
Hello.
I'm trying to make a module that uses a function defined in external C-file:
test00.pyx:
---------------------------
cdef extern void hello( int size )
---------------------------
test00_c.c:
---------------------------
#include <stdio.h>
void hello( int size )
{
printf("Hello! %d\n", size);
}
---------------------------
setup.py:
---------------------------
import glob
from distutils.core import setup
from distutils.extension import Extension
from Pyrex.Distutils import built_ext
TESTBASE = "build/temp.linux-i686-2.4"
setup(
name = "Test",
ext_modules = [
Extension( "test00", ["test00.pyx", "test00_c.c"],
extra_objects = glob.glob( "%s/*" % TESTBASE )
)
],
cmdclass = { 'build_ext': build_ext }
)
---------------------------
The module is built as follows:
$ python setup.py build_ext --inplace
The only problem is that when I run Python and import this module, no
functions are available (there's no hello function):
>>> import test00
>>> dir(test00)
['__builtins__', '__doc__', '__file__', '__name__']
I'm using Python 2.4.1 (but the version 2.4.2 will be also used) and Pyrex
0.9.3.1. What am I doing wrong?
More information about the Pyrex
mailing list