[SciPy-user] FYI: C++ Extensions for Python
david.grant at telus.net
Mon Nov 1 20:10:35 CST 2004
Bob Ippolito wrote:
> On Nov 1, 2004, at 19:03, David Grant wrote:
>> Bob Ippolito wrote:
>>> On Nov 1, 2004, at 17:51, David Grant wrote:
>>>> Just thought I'd share my experiences concerning looking for a way
>>>> to make python interfaces for C++ code (see my previous thread
>>>> about this):
>>>> pycxx - Looks like it requires one to modify all the C++ source,
>>>> adding PyObject pointers everywhere. I stayed away from this. I
>>>> don't want to modify the code if I have to (why should I have to?
>>>> the reason I'm making an interface is so that I can use the C++
>>>> code, and not touch it, thus avoiding creating bugs in the C++
>>>> code. If I WANTED to touch the C++ code I'd just re-write in python).
>>>> boost.python - Horrible documentation and horrible setup. Nothing
>>>> good to say about this. I spent more time on this than any other
>>>> method and made the least progress.
>>>> weave - was going to write a python routine which had some small
>>>> piece weave code. The weave code would be talking to a C++ library
>>>> or compiled python extension or something. I was able to make a
>>>> C++ library containing all my C++ code but then abandoned it after
>>>> that, to see if there were simpler methods
>>>> python.org method - http://docs.python.org/ext/simpleExample.html -
>>>> Similar to pycxx it involved altering the code
>>>> swig - at first it seemed like a lot of work to copy everything
>>>> from the .h files into the .i file. But then I realized you can
>>>> just use %include and it will use that stuff for swig. Simple
>>>> examples are given in the docs for both C and C++ which work well.
>>>> I like how it just generates an extra .c wrapper file which is then
>>>> compiled to a .o file and linked together will all the other .o
>>>> files and libraries (like -llapack) into a python extension, very
>>>> simply. Extend any methods or functions you want. I had a problem
>>>> because the C++ class overloaded the operator+ method, but there is
>>>> any easy to fix that in the docs, calling the python wrapper
>>>> __add__ instead.
>>>> So far swig is my choice. Boost.python looked good but I simple
>>>> couldn't get bjam to work!
>>> Uh, where does it say that you need to use bjam? It works just fine
>>> outside of that environment... take a look at Fusion
>>> <http://itamarst.org/software/> for example.
>> This page calls itself a quickstart but it doesn't say how to build
>> the shared library or what to do with the "Boost.Python" wrapper:
>> The next page in the tutorial which is very Windows specific (I don't
>> use Windows) and doesn't get me from A to B. ie. it should get a
>> hello.cpp python module but it doesn't. It seems to want me to run
>> boost in an example directory which is under /usr/share. Not the
>> right place to be building anything!
>> This page also doesn't talk about making the wrapper and/or what to
>> name it, or what to do with it. It only talks about bjam
> Ok, fine, so the tutorials and quickstart aren't the greatest. No
> real surprise there. Take a look at Fusion's setup.py.
Well I'll give them a 7/10 just for being pretty.
More information about the SciPy-user