|
Size: 2448
Comment: Standalone jamfile project fixed
|
Size: 2465
Comment: DA corrections
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 1: | Line 1: |
| #pragma section-numbers off |
|
| Line 4: | Line 6: |
| bjam is a standard tool for building boost library itself. Thus it is preferable way to build python extensions based on boost.python with bjam. | bjam is a standard tool for building boost library itself. Thus it is preferable way to build Python extensions based on ["boost.python"] with bjam. |
| Line 7: | Line 9: |
| However if you want to add external libraries in your extension (that is why you use boost.python, isn't it?), you must add them to dependency section: | However if you want to add external libraries in your extension (that is why you use boost.python, isn't it?), you must add them to the '''Jamfile''': |
| Line 12: | Line 14: |
| subproject libs/python/MyExtension ; ##################### if you put your dir in boost hierarchy | subproject libs/python/MyExtension ; ######## if you put your dir in boost hierarchy |
| Line 29: | Line 31: |
| <library-file>[[FULL_PATH_AND_LIBNAME]].lib # lib for Win32 | <library-file>[[FULL_PATH_AND_LIBNAME]] |
| Line 31: | Line 33: |
| <library-file>[[LIBNAME]].lib # lib for Win32 | <library-file>[[LIBNAME]] |
| Line 41: | Line 43: |
| Keeping your projects under boost hierarchy is often inconvenient. You may adjust Jamfile to build your extension from any place by: | Keeping your projects under boost hierarchy is often inconvenient. You may build your extension from any place by: |
| Line 43: | Line 45: |
| * changing the line {{{subproject}}} in the Jamfile to the {{{ | * changing the line {{{subproject}}} in the '''Jamfile''' to the {{{ |
| Line 47: | Line 49: |
| * copying {{{boost-build.jam}}} file to the root of your project tree and changing the following line inside it: {{{ | * creating '''boost-build.jam''' file in the root of your project tree like that: {{{ |
| Line 54: | Line 56: |
| * Make sure to link with ''boost_python'' or ''boost_python_debug'' library. |
|
| Line 59: | Line 63: |
| == Tips and tricks == | = Tips and tricks = |
Building Extensions with boost.python
Using bjam
bjam is a standard tool for building boost library itself. Thus it is preferable way to build Python extensions based on ["boost.python"] with bjam. Basic example listed in [http://www.boost.org/libs/python/doc/tutorial/doc/building_hello_world.html tutorial].
However if you want to add external libraries in your extension (that is why you use boost.python, isn't it?), you must add them to the Jamfile:
# NOTE: Change [[VARIABLES]] according to your system
# Specify our location in the boost project hierarchy
subproject libs/python/MyExtension ; ######## if you put your dir in boost hierarchy
# Include definitions needed for Python modules
SEARCH on python.jam = $(BOOST_BUILD_PATH) ;
include python.jam ;
# Declare a Python extension
extension Example
: # sources
Example.cpp
# dependencies
<dll>../build/boost_python
: # requirements
<include>[[FULL_PATH_INCLUDE_DIR]]
<include>[[RELATIVE_PATH_INCLUDE_DIR]]
<library-file>[[FULL_PATH_AND_LIBNAME]]
<library-path>[[PATH_TO_LIB]]
<library-file>[[LIBNAME]]
;
# Declare a test for the extension module
boost-python-runtest test1
: # Python test driver
test1.py
# extension modules to use
<pyd>Example ;Keeping your projects under boost hierarchy is often inconvenient. You may build your extension from any place by:
changing the line subproject in the Jamfile to the
project-root ;
and
creating boost-build.jam file in the root of your project tree like that:
boost-build [[PATH_TO_BOOST]]/tools/build ;
Using make
Make sure to link with boost_python or boost_python_debug library.
Using Windows IDE
Make sure you keep "Use Managed Extension" == No if you are using Visual Studio.NET.
Tips and tricks
To keep up with bjam rules you might want to have a dry run without actually building anything: {{{bjam -na }}}
To copy resulting executable to desired directory take a look at the stage rule.
To specify library in a platform-independent way you could do something like:
local libname
if $(NT)
{
libname = foo.lib
}
else
{
libname = libfoo.a
}
...
<library-file>$(libname)in the Jamfile.
