You are not logged in.
Hey
I want to write a python prgram, which uses a c++ class, i thought it would be best with boost::python
I have my class jumoSubClientHandler which inherits from subClientHandlerL
class jumoSubClientHandler: public subClientHandler{
public:
jumoSubClientHandler(std::string clientName="jumoClient");
private:
jumoInterface jumo;
public:
void printHelp();
private:
int extractProgramNumber(std::string data);
public:
bool analyseData(packetData_t data);
};
to use it in python i extended it with this:
using namespace boost::python;
// Boost.python definitions to expose classes to Python
BOOST_PYTHON_MODULE(jumoSubClientHandler) {
class_<jumoSubClientHandler> ("jumoSubClientHandler",init<std::string>())
.def("printHelp", &jumoSubClientHandler::printHelp())
;
}
for testing i just defined the function printHel and the constructor.
I can compile everything with gcc and create a .o file and then an .so file
(jumoSubClientHandler.so)
but if i want to import the class in python it does not work:
>>> import jumoSubClientHandler
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (initjumoSubClientHandler)
>>>
any idea what i do wrong?
best
Felix
Offline
@veloxid: Please show the exact compiler and linker invocation. You may have forgotten to link against a required library. Besides, check that Boost.Python is linked against the same Python version you're importing the module in.
Is Boost.Python mandatory for you? Imho there are binding tools and generators that are easier to use and more convenient (e.g. SIP or cython).
EDIT: For reference, the same question was also asked in the German Python forum.
Last edited by lunar (2012-03-28 16:06:35)
Offline
+1 boost.python is not very easy to use
Also worth mentioning: SWIG, which does python2 and 3, but also many other languages, and is also quite easy to use
Offline
IMHO I've found Boost Python much easier to use than SWIG when binding C++. Boost Python makes it possible to write nearly seamless Python/C++ code. Using Boost Python is actually quite straightforward once you've got past the initial learning curve.
Did you try implementing the examples in the Boost Python tutorial? Did those work?
- Good judgement comes from experience; experience comes from bad judgement. -- Mark Twain
- There's a remedy for everything but death. -- The wise fool, Sancho Panza
- The purpose of a system is what it does. -- Anthony Stafford Beer
Offline
I'd try naming the module differently from the name of your class. There may be a clash.
Offline