Quantitative Analysis
Parallel Processing
Numerical Analysis
C++ Multithreading
Python for Excel
Python Utilities
Services
Author

I. Python Object Browser.
II. Python to R Communicator.
III. Manipulation of piecewise polynomial functions.
IV. Building C++ projects.
1. Why not use bjam?
2. Installation of ots.make.
3. Code structure (ots.make).
4. Example. Building boost::python DLL.
5. Example. Building boost::python extension involving Cuda code.
6. Example. Building in-process COM DLL with embedded boost::python engine.
Downloads. Index. Contents.

Example. Building boost::python DLL.


he following make file builds boost::python dll for a variety of configurations and stores results into directories where the binaries would be automatically found by the framework. The script file may be found in the directory OTSProjects/Boost/Python.

import ots.make.options as opt

import ots.make.generator as gen

pg=gen.ParamsGenerator(

params=[

('version',[opt.Version.Release,opt.Version.Debug]),

('runtime',[opt.Runtime.Msvc9,opt.Runtime.Msvc71]),

('boost',[opt.Libs.Boost_1_40,opt.Libs.Boost_1_51]),

('python',[opt.Libs.Python25,opt.Libs.Python26,opt.Libs.Python27]),

('stlport',[None,opt.Libs.STLport])

],

libs=['stlport','python','boost']

)

while(pg.isValid()) :

d=pg.value()

version=d['version']

runtime=d['runtime']

boost=d['boost']

python=d['python']

stlport=d['stlport']

libs=d['libs']

pg.next()

if( python==opt.Libs.Python25 and runtime==opt.Runtime.Msvc9 ) :

continue

if( python in [opt.Libs.Python26,opt.Libs.Python27] and runtime==opt.Runtime.Msvc71 ) :

continue

files=[

(

boost.Python.sourcePath(),

[

"dict.cpp",

"errors.cpp",

"exec.cpp",

"import.cpp",

"list.cpp",

"long.cpp",

"module.cpp",

"numeric.cpp",

"object_operators.cpp",

"object_protocol.cpp",

"slice.cpp",

"str.cpp",

"tuple.cpp",

"wrapper.cpp",

]

),

(

boost.Python.sourcePath()+'converter',

[

"arg_to_python_base.cpp",

"builtin_converters.cpp",

"from_python.cpp",

"registry.cpp",

"type_id.cpp"

]

),

(

boost.Python.sourcePath()+'object',

[

"class.cpp",

"enum.cpp",

"function.cpp",

"function_doc_signature.cpp",

"inheritance.cpp",

"iterator.cpp",

"life_support.cpp",

"pickle_support.cpp",

"stl_iterator.cpp"

]

)

]

outputName=boost.Python.libFileRoot(

version=version,

runtime=runtime,

libs=libs

)

outputDir=boost.Python.libPath(

version=version,

runtime=runtime,

libs=libs

)

g=gen.MakeFile(

outputName=outputName,

outputDir=outputDir,

version=version,

runtime=runtime,

output=opt.Output.Dll,

libs=libs,

compile=[opt.Compile.Preprocessor("BOOST_PYTHON_SOURCE")],

files=files,

askBeforeDelete=False

)

g.make()

g.build()

The line

params=[

('version',[opt.Version.Release,opt.Version.Debug]),

('runtime',[opt.Runtime.Msvc9,opt.Runtime.Msvc71]),

('boost',[opt.Libs.Boost_1_40,opt.Libs.Boost_1_51]),

('python',[opt.Libs.Python25,opt.Libs.Python26,opt.Libs.Python27]),

('stlport',[None,opt.Libs.STLport])

],

is specification of the variety of configurations. The class gen.ParamsGenerator takes care of iterating through permutations.

The lines

if( python==opt.Libs.Python25 and runtime==opt.Runtime.Msvc9 ) :

continue

if( python in [opt.Libs.Python26,opt.Libs.Python27] and runtime==opt.Runtime.Msvc71 ) :

continue

reflect compatibility restrictions between MS runtime and versions of python.

The lines files=[...] enumerate the source files and their locations.

The function boost.Python.libFileRoot returns the name of the boost::python binary assigned by the framework for the given configuration. The function boost.Python.libPath returns the path to the binary.

The function g.make creates the make file. The function g.build() runs the make file.

After completion of the script the following directory structure would be created:


Figure

Each subdirectory contains the resulting binaries


Figure

and the make file


Figure

The make file doIt.mak for the displayed configuration would be composed as follows.

CP_OPTS = \

-DBOOST_ALL_DYN_LINK=1 \

-DBOOST_ALL_NO_LIB=1 \

-DBOOST_PYTHON_SOURCE \

-I"c:/boost_1_40_0" \

-I"c:/python26/include" \

-c \

/EHs \

/GR \

/GS \

/MDd \

/Ob0 \

/Od \

/W3 \

/Z7 \

/Zc:forScope \

/Zc:wchar_t \

/wd4675

LN_LIBS = python26.lib

LN_OPTS = \

/DLL \

/IMPLIB:$(OUTPUT_DIR)/$(RESULT_NAME).lib \

/INCREMENTAL:NO \

/LIBPATH:"c:/python26/libs" \

/MACHINE:X86 \

/NOLOGO \

/out:"$(OUTPUT_DIR)/$(RESULT_NAME).dll" \

/subsystem:console

OBJS = \

$(OBJ_DIR0)/dict.obj \

$(OBJ_DIR0)/errors.obj \

$(OBJ_DIR0)/exec.obj \

$(OBJ_DIR0)/import.obj \

$(OBJ_DIR0)/list.obj \

$(OBJ_DIR0)/long.obj \

$(OBJ_DIR0)/module.obj \

$(OBJ_DIR0)/numeric.obj \

$(OBJ_DIR0)/object_operators.obj \

$(OBJ_DIR0)/object_protocol.obj \

$(OBJ_DIR0)/slice.obj \

$(OBJ_DIR0)/str.obj \

$(OBJ_DIR0)/tuple.obj \

$(OBJ_DIR0)/wrapper.obj \

$(OBJ_DIR1)/arg_to_python_base.obj \

$(OBJ_DIR1)/builtin_converters.obj \

$(OBJ_DIR1)/from_python.obj \

$(OBJ_DIR1)/registry.obj \

$(OBJ_DIR1)/type_id.obj \

$(OBJ_DIR2)/class.obj \

$(OBJ_DIR2)/enum.obj \

$(OBJ_DIR2)/function.obj \

$(OBJ_DIR2)/function_doc_signature.obj \

$(OBJ_DIR2)/inheritance.obj \

$(OBJ_DIR2)/iterator.obj \

$(OBJ_DIR2)/life_support.obj \

$(OBJ_DIR2)/pickle_support.obj \

$(OBJ_DIR2)/stl_iterator.obj

OBJ_DIR0 = c:/OTSProjects/Boost/Python/bin/bPy_b140_debug_msvc9_py26/objs/dir0

OBJ_DIR1 = c:/OTSProjects/Boost/Python/bin/bPy_b140_debug_msvc9_py26/objs/dir1

OBJ_DIR2 = c:/OTSProjects/Boost/Python/bin/bPy_b140_debug_msvc9_py26/objs/dir2

OUTPUT_DIR = c:/OTSProjects/Boost/Python/bin/bPy_b140_debug_msvc9_py26

RESULT_NAME = bPy_b140_debug_msvc9_py26

SRC_DIR0 = c:/boost_1_40_0/libs/python/src

SRC_DIR1 = c:/boost_1_40_0/libs/python/src/converter

SRC_DIR2 = c:/boost_1_40_0/libs/python/src/object

goal : "$(OUTPUT_DIR)/$(RESULT_NAME).dll"

"$(OBJ_DIR0)/dict.obj" : "$(SRC_DIR0)/dict.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR0)/errors.obj" : "$(SRC_DIR0)/errors.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR0)/exec.obj" : "$(SRC_DIR0)/exec.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR0)/import.obj" : "$(SRC_DIR0)/import.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR0)/list.obj" : "$(SRC_DIR0)/list.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR0)/long.obj" : "$(SRC_DIR0)/long.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR0)/module.obj" : "$(SRC_DIR0)/module.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR0)/numeric.obj" : "$(SRC_DIR0)/numeric.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR0)/object_operators.obj" : "$(SRC_DIR0)/object_operators.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR0)/object_protocol.obj" : "$(SRC_DIR0)/object_protocol.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR0)/slice.obj" : "$(SRC_DIR0)/slice.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR0)/str.obj" : "$(SRC_DIR0)/str.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR0)/tuple.obj" : "$(SRC_DIR0)/tuple.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR0)/wrapper.obj" : "$(SRC_DIR0)/wrapper.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR1)/arg_to_python_base.obj" : "$(SRC_DIR1)/arg_to_python_base.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR1)/builtin_converters.obj" : "$(SRC_DIR1)/builtin_converters.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR1)/from_python.obj" : "$(SRC_DIR1)/from_python.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR1)/registry.obj" : "$(SRC_DIR1)/registry.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR1)/type_id.obj" : "$(SRC_DIR1)/type_id.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR2)/class.obj" : "$(SRC_DIR2)/class.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR2)/enum.obj" : "$(SRC_DIR2)/enum.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR2)/function.obj" : "$(SRC_DIR2)/function.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR2)/function_doc_signature.obj" : "$(SRC_DIR2)/function_doc_signature.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR2)/inheritance.obj" : "$(SRC_DIR2)/inheritance.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR2)/iterator.obj" : "$(SRC_DIR2)/iterator.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR2)/life_support.obj" : "$(SRC_DIR2)/life_support.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR2)/pickle_support.obj" : "$(SRC_DIR2)/pickle_support.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OBJ_DIR2)/stl_iterator.obj" : "$(SRC_DIR2)/stl_iterator.cpp"

cl $? -Fo$@ $(CP_OPTS)

"$(OUTPUT_DIR)/$(RESULT_NAME).dll" : $(OBJS)

link $(LN_OPTS) $(OBJS) $(LN_LIBS)

mt -nologo -manifest "$(OUTPUT_DIR)/$(RESULT_NAME).dll.manifest" -outputresource:"$(OUTPUT_DIR)/$(RESULT_NAME).dll;#2"





Downloads. Index. Contents.


















Copyright 2007