I wasn't able to get the basic quickstart example for Boost.Python working without some modifications, so I wanted to document it for others.
Here are the various issues I encountered with the default example:
- The Bjam file (in the root of boost or in the quickstart, i'm not sure) defaults to threading=single, but something else is defaulting to threading=multi, so they are incompatible (shows up as saying the
boost_python-vcXXX-mt-gd-1_XX.lib
is not found when it just generatedboost_python-vcXXX-gd-1_XX.lib
). Manually specifyingthreading=multi
for the bjam commands seems to fix things. - I wanted to get this going with boost 1.57.0, but there was a change to the boost::build directory structure in 1.56+ that hasn't been reflected in the quickstarts boost-build.jam file, so I reverted back to 1.55.0.
- Visual Studio 2010 (msvc-10.0) has a bug that keeps it from building the quickstart\embedding.cpp example. I've done everything below with Visual Studio 2013 (msvc-12.0).
- The rules to build the test_embed test don't seem to be creating a main(), leading to an unresolved external _mainCRTStartup symbol. (It looks like it is trying to make a test executable from the embedding.exe + instead of embedding.cpp)
Here's what I did to make things work.
-
Install Python 2.7 from default install of python. (Maybe I'll try this again in the future with Python 3.) This doesn't include the builds with debug info (if you want that, you have to build from source). At first I thought this might have been causing me problems, but it appears that Boost.Python figures things out (as far as the correct linking). I've installed my version into
C:\Python27-32\
, this will allow me to install other versions along side (C:\Python27-64, C:\Python34-32, etc). -
Get the user-config.jam file correct! (This is by far the most important step!) I used:
import toolset : using ; using msvc : 12.0 ; using python : 2.7 # Version : C:\\Python27-32\\python.exe # Interpreter : C:\\Python27-32\\include # inc dir : C:\\Pyhton27-32\\libs # link libs : # conditions ;
-
Unzip boost (to
f:\tmp\boost_1_55_0
). -
Change to that directory (
cd f:\tmp\boost_1_55_0
) -
Bootstrap the bjam executable (
bootstrap.bat
) -
Change to the quickstart example directory (
cd libs\python\example\quickstart
) -
Run the "extending" test (this should build the correct version of Boost.Python as well) with the command:
f:\tmp\boost_1_55_0\bjam.exe threading=multi toolset=msvc-12.0 --verbose-test test_ext
. It should do a bunch of building, then run the test, one of the last lines should be something like**passed** bin\test_ext.test\msvc-12.0\release\threading-multi\test_ext.test
-
Test the "embedding" application. Since the bjam file is broken, we have to do it by hand:
- Build the "embedding" application:
f:\tmp\boost_1_55_0\bjam.exe threading=multi toolset=msvc-12.0 --verbose-test embedding
- Copy the needed DLL:
copy ..\..\..\..\bin.v2\libs\python\build\msvc-12.0\debug\threading-multi\boost_python-vc120-mt-gd-1_55.dll .
- Run the app with the correct input:
bin\msvc-12.0\debug\threading-multi\embedding.exe script.py
- You should see a bunch of python output (including a traceback, which is expected), and in the end 'No errors detected.'
- Build the "embedding" application:
If you want to do a 64-bit build as well, use this.
user-config.jam
import toolset : using ;
using msvc : 12.0 ;
using python
: 2.7 # Version
: C:\\Python27-32\\python.exe # Interpreter
: C:\\Python27-32\\include # inc dir
: C:\\Python27-32\\libs # link libs
: # conditions
;
using python
: 2.7 # Version
: C:\\Python27-32\\python.exe # Interpreter
: C:\\Python27-32\\include # inc dir
: C:\\Python27-32\\libs # link libs
: <address-model>64 # conditions
;
command: f:\tmp\boost_1_55_0\bjam.exe threading=multi toolset=msvc-12.0 address-model=64 --verbose-test test_ext
Bonus: You can add a -jN
to multi thread the build and make it go much faster. Just subsitute N with the number of processors you want to use.
Works for python 2 but not for 3.4. Running the command to run the extending test does not display any errors, but it does not build the .exe file or attempt to run any tests.
EDIT: This happens with python 2 now. Presumably an issue with something I've done rather than the python version, but I don't know what it is.