[C++-sig] Boost.Python hello tutorial issue ?

Aurélien MAIGNAN amaignan at gmail.com
Fri May 30 16:08:34 CEST 2008

I have just started to see wrapping C++/Python and choose to use
boost.Python libs and further Py++ once mastered boost.Python.

So I read their tutorial introduction :

Ok so i install Boost and choose Python lib at setup and msvc 8.0 as
compiler. (got 2005 express version).
Boost has been installed in this abs path : C:\Program

Then i build the BJam tools usign the .bat isued with the Boost.Python
I add the path in PATH Env Var.

Next and prior to use the bjam command in the tutorial directory (where
hello.cpp, hello.py and Jamroot files are)
i modified the user-config.jam file according to the tutorial :
This file is located in : C:\Program Files\boost\boost_1_35_0\tools\build\v2
here is  the modifications :

i added this :
#  Configure msvc (default version, searched in standard location
#  and PATH).
  using msvc : 8.0 ;

and this :
#  Python configuration
using python : 2.5 : C:/Python25 ;

the rest of the file hasn't change at all.

I doesn't touch the Jamroot file either

( **** note you can ignore the following it is another minor issue : ****

ok it is not totally right : i wish to change the default use-project rule
from :
use-project boost
  : ../../../.. ;   => default one
use-project boost
  : "$(BOOST_ROOT)  ;

where BOOST_ROOT is a user Env Var which store the path : C:\Program

But that doesn't build using bjam command : the following error happend :
*** argument error
* rule use-project ( id : where )
* called with: ( boost :  )
* missing argument where

so finally i changed it to

use-project boost
  : "C:/Program Files/boost/boost_1_35_0" ;

but i would rather use the Env Var if possible

 **** end of the minor issue description **** )

so ok I launched bjam and after a while it finnished building the lib files,
and make me use the param *--preserve-test-targets* to bjam as indicated in
the tutorial for the 1.35 version.

 --> But the problem is that usign hello.py doesn't work due to the fact the
library weren't found by python.

Indeed the libs are generated in this paths :
and :

There is no way Python are aware of this new Libs !
Maybe i wrong but i though that bjam automated the creation of the library
for python and put the files where they need to be,
A clue of this is the fact that we needed to add :
#  Python configuration
using python : 2.5 : C:/Python25 ;
in the user-config.jam file, so i guessed that bjam would create
automatically the directory of the new module and put the libs there.

In order to make it work i had to copying the hello_ext.lib file to the
Python lib directory : C:\Python25\libs

and i had to create manually this directory :
In this directory I copied our libs files :
And create also another file : __init__.py that contain the following :

import sys


# this brings in the DLL (pyd)
from hello_ext import *

And after this the new module was known from python and
hello.py work !
to sum up : does bjam automatically generate the module directory and plant
in the lib needed (and the __init__.py file) as I though it was
Or does i need to do this manually (and create another script/make like file
to automatize this) ?

Note 1 : this not my idea, in order to resolve my issue i found this on the
web wich is a similar case :
/Note 1

Note 2 : in this thread one advise to modified the Jamroot file and add this

# Declare a Python extension
python-extension _**name of ext goes here** # Declare a Python extension
  : **name of CPP with wrapper class(es) goes here**    # Source
  : <include>**your includes go here**
    <define>**your defines go here**
  : <library-path>**your lib path goes

so i putted this :

# Declare a Python extension
python-extension hello_ext # Declare a Python extension
  : hello.cpp    # Source
  #: <include>**your includes go here**
  #  <define>**your defines go here**
  #: <library-path>**your lib path goes here**

But bjam doesn't work anymore (some error that imply some core .jam file
that is not from me) so I removed this and return to the the default vesion
# Declare the three extension modules.  You can specify multiple
# source files after the colon separated by spaces.
python-extension hello_ext : hello.cpp ;
/Note 2

THANKs for considering this post, a little long ^^ and excuse my english ;)

MAIGNAN Aurélien
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080530/dcb9d8e7/attachment.htm>

More information about the Cplusplus-sig mailing list