python extensions: including project local headers

J Kenneth King james at agentultra.com
Thu Oct 23 11:36:44 EDT 2008


Hey everyone,

I'm working on a python extension wrapper around Rob Hess'
implementation of a SIFT feature detector. I'm working on a
computer-vision based project that requires interfacing with Python at
the higher layers, so I figured the best way to handle this would be in
C (since my initial implementation in python was ungodly and slow). 

I can get distutils to compile the extension and install it in the
python path, but when I go to import it I get the wonderful exception:

ImportError: /usr/lib/python2.5/site-packages/pysift.so: undefined
symbol: _sift_features

Of course, _sift_features is a function defined in his header that I'm
#including in my extension.

His sources are sitting in my project root under sift/ while my source
is under src/ -- My setup.py is as follows:

[code]

from distutils.core import setup, Extension

pysift = Extension('pysift',
                   include_dirs = ['sift/include'],
                   sources = ['src/pysift.c'],
                   extra_link_args = ['-lm', '-lcv', '-lcxcore',
                                      '-lhighgui', '-lcvaux'])

setup(name = 'pysift',
      version = '0.0',
      description = 'A SIFT feature detection package',
      author = 'James Kenneth King',
      author_email = "james at agentultra.com",
      url = "http://agentultra.com/",
      long_description = """
      A python extension package for detecting SIFT
      features using Rob Hess' C implementation.

      http://web.engr.oregonstate.edu/~hess/

      Original SIFT feature descriptors by David Lowe
      and patented by the University of British Columbia.
      """,
      ext_modules = [pysift])

[/code]

And the include to Rob's header file is on the second line of pysift.c:

#include "sift.h"

The weird thing (to me in my somewhat hackish knowledge of C) is that I
can use all the #defines from sift.h with no complaints from the
preprocessor (in fact, there are no complaints at all from the compiler
when compiling the extension module).

Once I get this bugger working, I'll be setting up a project page to
share sources and will also be releasing extension wrappers to the
OpenCV libraries.

I've never released any code before so any help getting this right and
proper for the community would be greatly appreciated.

Cheers.



More information about the Python-list mailing list