473,889 Members | 1,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

python extensions: including project local headers


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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. from distutils.core import setup, Extension
  3.  
  4. pysift = Extension('pysift',
  5. include_dirs = ['sift/include'],
  6. sources = ['src/pysift.c'],
  7. extra_link_args = ['-lm', '-lcv', '-lcxcore',
  8. '-lhighgui', '-lcvaux'])
  9.  
  10. setup(name = 'pysift',
  11. version = '0.0',
  12. description = 'A SIFT feature detection package',
  13. author = 'James Kenneth King',
  14. author_email = "ja***@agentultra.com",
  15. url = "http://agentultra.com/",
  16. long_description = """
  17. A python extension package for detecting SIFT
  18. features using Rob Hess' C implementation.
  19.  
  20. http://web.engr.oregonstate.edu/~hess/
  21.  
  22. Original SIFT feature descriptors by David Lowe
  23. and patented by the University of British Columbia.
  24. """,
  25. ext_modules = [pysift])
  26.  
  27.  
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.
Oct 23 '08 #1
8 1697

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.

HTH
Philip
Oct 23 '08 #2
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'
implementati on 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.

Also, you don't want to pass the list of libraries with extra_link_args .
Instead, use libraries=.

pysift = Extension('pysi ft',
include_dirs = ['sift/include'],
sources = ['src/pysift.c'],
libraries = ['feat', 'cv', 'cxcore', 'highgui',
'cvaux', 'm'])

--
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

Oct 23 '08 #3
Robert Kern <ro*********@gm ail.comwrites:
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'
implementatio n 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('pysi ft',
include_dirs = ['sift/include'],
sources = ['src/pysift.c'],
libraries = ['feat', 'cv', 'cxcore', 'highgui',
'cvaux', 'm'])
Thanks for taking a moment to help me out. :)
Oct 23 '08 #4
J Kenneth King wrote:
Robert Kern <ro*********@gm ail.comwrites:
>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'
implementati on 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:

ImportErro r: /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_feature s. 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?
No, you would add the source file names to the sources= list.

--
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

Oct 23 '08 #5
Philip Semanchuk <ph****@semanch uk.comwrites:
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'
implementati on 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?

Thanks for the reply. Python has spoiled me and my C is rather
rusty. :)
Oct 23 '08 #6

On Oct 23, 2008, at 3:18 PM, J Kenneth King wrote:
Philip Semanchuk <ph****@semanch uk.comwrites:
>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'
implementatio n 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.
That's true, and it sounds like you've got that part working.

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?

Thanks for the reply. Python has spoiled me and my C is rather
rusty. :)
I don't know how to get setup.py to build a shared object separately.
I am in the same Python/C situation as you. I'm scrubbing the rust off
of my C skills and I'm also a n00b at developing extensions. I've
learned a lot from looking at other people's setup code, so maybe I
can help you there.

My posix_ipc module links to the realtime lib "rt" and here's the
relevant snippets of setup.py:

------------------------------
import distutils.core as duc

libraries = [ ]

libraries.appen d("rt")

source_files = ["posix_ipc_modu le.c"]

ext_modules = [ duc.Extension(" posix_ipc",
source_files,
define_macros=d efine_macros,
libraries=libra ries
)
]

duc.setup(name= "posix_ipc" , version=VERSION , ext_modules=ext _modules)

------------------------------

You can download the whole thing here if you want to examine all the
code:
http://semanchuk.com/philip/posix_ipc/

HTH
Philip
Oct 23 '08 #7
J Kenneth King wrote:
Philip Semanchuk <ph****@semanch uk.comwrites:
>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'
implementatio n 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

Oct 23 '08 #8
Philip Semanchuk <ph****@semanch uk.comwrites:
On Oct 23, 2008, at 3:18 PM, J Kenneth King wrote:
>Philip Semanchuk <ph****@semanch uk.comwrites:
>>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'
implementati on 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:

ImportErro r: /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.

That's true, and it sounds like you've got that part working.

>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?

Thanks for the reply. Python has spoiled me and my C is rather
rusty. :)

I don't know how to get setup.py to build a shared object separately.
I am in the same Python/C situation as you. I'm scrubbing the rust off
of my C skills and I'm also a n00b at developing extensions. I've
learned a lot from looking at other people's setup code, so maybe I
can help you there.

My posix_ipc module links to the realtime lib "rt" and here's the
relevant snippets of setup.py:

------------------------------
import distutils.core as duc

libraries = [ ]

libraries.appen d("rt")

source_files = ["posix_ipc_modu le.c"]

ext_modules = [ duc.Extension(" posix_ipc",
source_files,
define_macros=d efine_macros,
libraries=libra ries
)
]

duc.setup(name= "posix_ipc" , version=VERSION , ext_modules=ext _modules)

------------------------------

You can download the whole thing here if you want to examine all the
code:
http://semanchuk.com/philip/posix_ipc/

HTH
Philip
I'll take a look, thanks! :)
Oct 24 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3859
by: Logan | last post by:
Several people asked me for the following HOWTO, so I decided to post it here (though it is still very 'alpha' and might contain many (?) mistakes; didn't test what I wrote, but wrote it - more or less - during my own installation of Python 2.3 on Fedora Core 1 Linux for a friend of mine). Anyway, HTH, L.
7
3677
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc. And i have things to offer, and to request. And a lot of ideas, but who needs them.... here's an example (from type_struct.py):
36
6432
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but something I'll need in this case is some experience-based set of rules about how to use python in this context. For example... is defining readonly attributes in classes worth the hassle ? Does duck-typing scale well in complex
3
7496
by: Chris Paul | last post by:
I'm having trouble with PHP & PostgreSQL/OpenLDAP/Apache on Windows. I've set this up countless times on BSD (piece of cake) but I'm trying to do this on Windows now so that my developer can work on her local machine. Everything looks pretty good. OpenLDAP/cygwin works great. PostgreSQL works great. Apache runs. PHP runs. But when I try to connect to my PostgreSQL server using PHPPgAdmin, I
0
9962
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9810
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11198
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10791
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9609
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7150
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5829
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3256
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.