newbie question: python and c++ objects

Alex Martelli alex at magenta.com
Sun Aug 6 03:53:48 EDT 2000


"zander" <zander at dont.net> wrote in message
news:Sb%i5.155$wh7.26225 at sapphire.mtt.net...
> Hello All
>
> I am working on a game engine and I would like use python as my scripting
> language. Basicly I have a large amount of c++ objects (or libraries) and
> usually what I do to produce a new game is to create a c++ program to join
> all the objects the way I would like them to.
>
> So my question is, is it possible to use c++ libraries in python.If
possible
> could you explain how.

Check out http://cxx.sourgeforge.net/ which hosts Paul Dubois' excellent
"CXX Project".  It works a treat, and makes it a snap to write Python
extensions in C++ rather than C -- in fact, with this support it's
_easier_ to write extensions in C++ than it is in C.  Of course, the
key side benefit for you will be that your extensions will just be glue
exposing parts or all of your existing class libraries.

Some caveats apply, depending on your platform, just as they would for
C, but more forcefully.  Extensions must be built with the same
compiler as used for Python itself and compatible settings: this tends
to be a hot issue on Windows, where several compilers are widespread
and (at least with Microsoft's) it's easy to create a DLL and an EXE
that can't really talk to each other (most often because they haven't
both been generated to use the same dynamic runtime DLL -- either both
MSVCRT.DLL, which is the one normal Python uses, _or_ both MSVCRTD.DLL
for debugging, which is the one python_d. exe &c use).

I hear there are notes on the net on how to use Borland's free 5.5 C++
compiler for Python extensions, but I don't have an URL, sorry.

On Linux, this tends to be less of a problem, though.


Alex








More information about the Python-list mailing list