How do I interface to C++ objects from Python?

Depending on your requirements, there are many approaches. To do this manually, begin by reading Extending and Embedding the Python Interpreter. Realize that for the Python run-time system, there isn’t a whole lot of difference between C and C++ — so the strategy of building a new Python type around a C structure (pointer) type will also work for C++ objects.

If you don’t want to work at the Python C API level, you can use tools like Pyrex and SWIG. The former lets you write Python-like code for the interface, the latter uses special interface specifications to generate bindings for Python as well as several other languages.

There are also a number of more specialized tools available for C++, including SIP, CXX, Boost, and Weave.

CATEGORY: extending

 

Comment:

It is also possible to use Py++( http://language-binding.net/pyplusplus/pyplusplus.html ) Py++ is an object-oriented framework for creating a code generator for Boost.Python library. Py++ uses few different programming paradigms to help you to expose C++ declarations to Python. This code generator will not stand on your way. It will guide you through the whole process. It will raise warnings in the case you are doing something wrong with a link to the explanation. And the most important it will save your time - you will not have to update code generator script every time source code is changed. Usage example: http://python-ogre.python-hosting.com/ Comparison( read 2 last post ) http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=2943&sid=4d1acf3b9bc0dd63f174dcd16f851fa6

Posted by Alex (2006-12-24)

A Django site. this page was rendered by a django application in 0.04s 2008-11-21 14:28:08.608809. hosted by webfaction.