[C++-sig] call C-functions (by reference) from Python (using Boost.Python)

Lutz.Lauterbach at qimonda.com Lutz.Lauterbach at qimonda.com
Fri Dec 15 10:39:39 CET 2006

I want to thank the guys in the forum for all the hints and as a result
I would like to share my outcomes/conclusions with you to avoid the pain
for you that I have already gone through. Please check out the attached
file. There you find C-functions wrapped with Boost.Python including
  *creating arrays in C and passing them to Python

I work with Win2k. After installing Boost.Python (better to say
uncompressing/unzipping) version V1.33.1 and MinGW version 5.0.2. (with
gcc version 3.4.2 (mingw-special)) I adapted the hello.cpp file in
directory <Boost installation>\libs\python\example\tutorial\hello.cpp.
To make the thing work you need to put the include file
"convenience.pypp.hpp" in the same directory (or in the include path).
This one I also slightly adapted, because otherwise it did not compile
with these Boost.Python/MinGW versions installed.
To finally compile the code on my computer with Python version 2.2 I had
to call in the above mentioned directory the command:

   bjam "-sTOOLS=mingw" "-sMINGW_ROOT_DIRECTORY=C:\Programs\MinGW"
"-sPYTHON_VERSION=2.2" "-sPYTHON_ROOT=C:\Progra~1\Python22"

This creates a "bin" directory and the two important module files
(hello.pyd & boost_python.dll) in some subdirectories inside "bin",
which I had to copy to the Python installation directory.
Then I could call a C-function (from my created module "hello") like
this e.g.:
>>> from hello import *
>>> jz_array(3)
    ([0.0, 1.0, 2.0], [0.0, -1.0, -2.0])

Good luck & best regards, Lutz Lauterbach.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: c_functions.zip
Type: application/x-zip-compressed
Size: 3178 bytes
Desc: c_functions.zip
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20061215/367ca030/attachment.bin>

More information about the Cplusplus-sig mailing list