python extensions: including project local headers

Robert Kern robert.kern at gmail.com
Thu Oct 23 18:26:12 EDT 2008


J Kenneth King wrote:
> Philip Semanchuk <philip at semanchuk.com> writes:
> 
>> On Oct 23, 2008, at 11:36 AM, J Kenneth King wrote:
>>
>>> 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
>>
>> Kenneth,
>> You're close but not interpreting the error quite correctly. This
>> isn't an error from the compiler or preprocessor, it's a library
>> error. Assuming this is dynamically linked, your OS is reporting that,
>> at runtime, it can't find the library that contains _sift_features.
>> Make sure that it's somewhere where your OS can find it.
> 
> This is basically what I was looking for help with. So far the project
> directory is:
> 
> /pysift
>   /sift
>     ..
>     /include
>       ..
>       sift.h
>     /src
>       ..
>       sift.c
>   /src
>     pysift.c
>   setup.py
> 
> I thought I could just #include "sift.h" in pysift.c as long as
> distutils passed the right -I path to gcc.
> 
> Maybe I should compile the sift code as a shared object and link it to
> my extension? How would I get distutils to build the makefile and tell
> gcc how to link it?

I don't recommend doing that, if you can avoid it. distutils does not really 
support that. If you can get the sift files to compile under distutils as part 
of the Extension, that is by far the best option.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list