5
votes

I am trying to follow this tutorial on wrapping C++ code for python for Windows.I installed python.Downloaded the latest version of boost(1_55).First I ran bootstrap.bat to build bjam.exe.Next, I configured boost_1_55_0\tools\build\v2\user-config.jam to use msvc10 compiler and added the path to python installation. Now,based on the tutorial :

Now we are ready... Be sure to cd to libs/python/example/tutorial where the tutorial "hello.cpp" and the "Jamroot" is situated.

Finally:

bjam

Trying to run bjam in that directory gives me : "bjam is not recognized as internal or external command" error.What have I missed here? Should user-config.jam reside in another location?Or bjam added to system path?

UPDATE:

Ok.Thanks to @john I had to add bjam to system path.But now,running it,hello_ext.lib is created in \boost_1_55_0\libs\python\example\tutorial\bin\msvc-11.0\debug but not DLL.Based on the tutorial I should get DLL file for the extension.Now, I am not sure how python links with extension.But if I assume it does like C++ then it should have linked with hello_ext.lib.But if run :

python hello.py

which contains imported method from the extension ,the python runtime crashes.Isn't there a comprehensive tutorial on this workflow?Boost doc sucks completely on this.

1
Presumably bjam isn't on your PATH. Use the system control panel to add the directory containing bjam to your PATH.john
Can't really help you bjam but I usually manage to avoid bjam on unix to compile boost-python projects. I just make sure to include the correct header paths and dynamic library paths in the makefile. I'm pretty sure something similar can be done for windows and your IDE. Good luckuser2245644
Don't use bjam. I suggest using scons instead.Faheem Mitha

1 Answers

4
votes

This worked for me:

1.) unzip boost_1_55_0.zip

2.) Prepare to use the Boost Library Binaries

Go to the boost_1_55_0 root directory and open a command prompt and type following commands:

Bootstrap

3.) Find user-config.jam:

Type following in the command prompt:

ECHO %HOMEDRIVE%%HOMEPATH%

4.) If the user-config.jam is in your homedrive directory please change it there as followed:

ATTENTION:

The .jam language rates a “whitespace” as a separation of arguments!

# -------------------
# MSVC configuration.
# -------------------

# Configure msvc (default version, searched for in standard locations and PATH).
# using msvc ;

# Configure specific msvc version (searched for in standard locations and PATH).
using msvc : 10.0 : C:\\app\\tools\\MSVisualStudio2010\\VC\\bin\\cl.exe ;

….

# ---------------------
# Python configuration.
# ---------------------

# Configure specific Python version.
# using python : 3.1 : /usr/bin/python3 : /usr/include/python3.1 : /usr/lib ;

using python 
    : 2.5                   # Version
    : C:\\app\\tools\\Python25\\python.exe      # Python Path
    : C:\\app\\tools\\Python25\\include         # include path
    : C:\\app\\tools\\Python25\\libs            # lib path(s)
    : <define>BOOST_ALL_NO_LIB=1
    ;

5.) Build the Libraries AFTER configuration!!

Go to the boost_1_55_0 root directory and open a command prompt and type following commands:

.\b2

6.) Copy the user-config.jam to \boost_1_55_0\libs\python\example\tutorial 7.) Go further to \boost_1_55_0\stage\lib\

Rename libboost_python-vc100-mt-gd-1_55.lib to boost_python-vc100-mt-gd-1_55.lib and copy it to

\boost_1_55_0\libs\python\example\tutorial

8.) Now you should have all of these files in the \boost_1_55_0\libs\python\example\tutorial directory

hello.cpp
hello.py
user-config.jam
Jamroot
boost_python-vc100-mt-gd-1_55.lib
bjam.exe

9.) Open a command prompt in \boost_1_55_0\libs\python\example\tutorial

And type following command:

bjam

10.) After successful building..

You should have this file in the directory:

hello_ext.dll

rename this file to:

hello_ext.pyd