Wrapping C functions in Pyrex and distutils problem

T

TPJ

I'm trying to get a wrapper for my C code in order to be able to use it
as a module in Python. I'm doing it as follows:

C code (file_c.c):
-------------------------------
#include <stdio.h>

void hello( int size )
{
printf("Hello! %d\n", size);
}
-------------------------------

Pyrex code (file.pyx):
-------------------------------
cdef extern void hello( int size )
-------------------------------

Python code (setup.py):
-------------------------------
from distutils.core import setup
from distutils.extension import Extension
from Pyrex.Distutils import build_ext

setup(
name = "File",
ext_modules=[
Extension( "file", ["file.pyx", "file_c.c"] )
],
cmdclass = { 'build_ext': build_ext }
)
-------------------------------

After

$ python setup.py build_ext --inplace

all is compiled ok, but the shared library (file.so) is built only from
one file (file_c.o) - and the second object file (file.o) is ignored.
Of course it's imposible to import such a module in Python.

What am I doing wrong?
 
D

Diez B. Roggisch

Use additional_objects:


--------
LINKBASE = "link-4.1b"

setup(
name = "LinkWrapper",
ext_modules = [
Extension("link", ["link.pyx"],
include_dirs = ["%s/include" % LINKBASE],
extra_objects = glob.glob("%s/obj/*" % LINKBASE),
)
],
cmdclass = {'build_ext': build_ext}
)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top