Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > ImportError when trying to import own C++ module

Thread Tools

ImportError when trying to import own C++ module

Jan Drugowitsch
Posts: n/a
Hi everyone!

I am trying to access a C++ class which is wrapped in a Python object from
another C++ class which is also wrapped in a Python object. I have used the
following file structure:

Declaration of AClass
typedef of PyObject containing AClass

Including AClass.h
Implementation of AClass

Including AClass.h
Python interface to access AClass

Including AClass.h
Declaration of BClass
Implementation of BClass
Python interface to access BClass

AClass has the methods
unsigned int value() const; // reading private value
void setValue(const unsiged int); // setting private value

BClass has the method
unsigned int value(const AClass* aclass) const; // returning aclass->value()

(remember: just a proof-of-concept)

I'm using DistUtils to compile the libraries. links AClass.cpp and
PyAClass.cpp, links BClass.cpp and AClass.cpp.
Using AClass in Python works without problems, importing BClass, however,
gives the following error:

>>> import BClass

Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: ./ undefined symbol: _ZNK6AClass5valueEv, however, seems to contain that symbol:

% nm | grep _ZNK6AClass5valueEv
U _ZNK6AClass5valueEv

Any ideas what can go wrong there?
Any hints are appreciated


P.S.: I'm sorry if this question has been asked a thousand times. It is very
hard to search for in the archives as 'ImportError' is usually a bug in some
software and no solution is given to resolve it.

Version: GnuPG v1.2.4 (GNU/Linux)


Reply With Quote
Diez B. Roggisch
Posts: n/a

> % nm | grep _ZNK6AClass5valueEv
> U _ZNK6AClass5valueEv

From the nm manpage:

"U" The symbol is undefined.


Diez B. Roggisch
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
imp.find_module don't found my module but standard import statement can import this module… why ? Stéphane Klein Python 0 07-05-2011 07:36 AM
Why 'import module' will not import but the directorymodule? Peng Yu Python 0 10-31-2009 11:51 PM
SWIG/IDLE/Python: F5 works but "import SHIP" gives "ImportError: dynamic module does not define init function (initSHIP)" Bill Davy Python 0 05-12-2005 08:48 AM
Handling import conflicts when module has the same name as a library module that it needs to import? plb Python 0 02-08-2005 01:08 PM
Handling import conflicts when module has the same name as a library module that it needs to import? plb Python 0 02-08-2005 01:01 PM