[C++-sig] Advice sought on making a large C++ application a Python extension

Ben Fitzpatrick bfitzpatrick at vtiinstruments.com
Tue Sep 7 16:45:53 CEST 2010


David,

I'm still a newbie on this list myself, but I will tell you that for the larger project which we were attempting to wrap, we had excellent luck with Gustavo Carniero's Pybindgen project. We found it to be much simpler to work with than boost.python and py++, and also it compiled much faster.

As to how to make your functionality available with a Python extension - I'm not sure exactly what kind of app you have, but is it possible to make the Python portion only an interface to the underlying C++ code? That's basically what we did with our application - write a wrapper layer on top of the ordinary C++ API that implemented a Python API. This also allowed us to build the C++ application, and then with an additional build step (in GNU make) we were able to compile the python interface layer.

It may be that you need to make all of your classes into python extensions, in which case py++ and boost.python may be the better tool, I am not certain, but for writing just an interface layer, our experience was that Pybindgen was easier.

Hope this helps!

-Ben

-----Original Message-----
From: cplusplus-sig-bounces+bfitzpatrick=vtiinstruments.com at python.org [mailto:cplusplus-sig-bounces+bfitzpatrick=vtiinstruments.com at python.org] On Behalf Of David Aldrich
Sent: Monday, September 06, 2010 11:16 AM
To: Development of Python/C++ integration
Subject: [C++-sig] Advice sought on making a large C++ application a Python extension

Hi

We have a large C++ application that we develop in-house. It consists of a large number of source files, some of which are linked directly and some of which are first built as static libraries.

It has been suggested that we make the application's functionality available as a Python extension.  Simplistically speaking, we could then let users replace our C++ main() by a Python script.

I have only looked at the boost.python tutorial that demonstrates a 'Hello world' Python extension.  For our project we would be dealing with something very much bigger, with many classes, singleton classes and (possibly) global data.  My question is, would it be practical to make all of those entities Python extensions?

We would also want to continue to support the application as a wholly C++ application.   Currently, we use gnu make to build it.  Would I have to add a parallel build system using bjam to build the extensions? And then maintain both make's makefiles and bjam's Jamroot files?

Can .pyd files be loaded by the C++ linker?

Any advice would be gratefully received.

Best regards

David

=================================================================
David Aldrich, NEC Telecom MODUS, Ltd,
Cleeve Road, Leatherhead, Surrey, KT22 7SA, UK
Direct tel. +44 (0) 1372 381857
=================================================================

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig at python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


More information about the Cplusplus-sig mailing list