python extensions: including project local headers

J Kenneth King james at agentultra.com
Thu Oct 23 18:11:19 CEST 2008


Robert Kern <robert.kern at gmail.com> writes:

> Philip Semanchuk wrote:
>>
>> 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.
>
> It looks like the library implementing it was not linked into the
> extension. sift_features() is not part of OpenCV.
>
> James, are you including the source of Rob Hess's implementation with
> your extension, or are you trying to link against an already installed
> version of the library? If the former, you need to add the C sources
> to the pysift Extension(). If the latter, you need to add the name of
> the library to the list of libraries.

I'm including Rob Hess' sources with the extension.

Would that mean I should add library_dirs to Extension() to point to the
sources in the project's path?

> Also, you don't want to pass the list of libraries with
> extra_link_args. Instead, use libraries=.
>
> pysift = Extension('pysift',
>                    include_dirs = ['sift/include'],
>                    sources = ['src/pysift.c'],
>                    libraries = ['feat', 'cv', 'cxcore', 'highgui',
>                                 'cvaux', 'm'])

Thanks for taking a moment to help me out. :)



More information about the Python-list mailing list