# Building an Extension Module

The build process for Boost is currently undergoing some evolution, and, it is to be hoped, improvement. The following facts may help:

- Makefiles for various platforms reside in the Boost subdirectory `libs/python/build`:
  - como.mak (Comeau C++ on Linux)
  - linux_gcc.mak (GCC on Linux/Unix)
  - gcc.mak (older makefile for GCC on Linux/Unix. Deprecated.)
  - mingw32.mak (highly-specialized makefile for mingw32 (Win32-targeted) GCC. Read the header comment).
  - tru64_cxx.mak (Compaq Alpha).
- A project workspace for Microsoft Visual Studio is provided at `libs/python/build/build.dsw`. The include paths for this project may need to be changed for your installation. They currently assume that python has been installed at `c:\tools\python`. Three configurations of all targets are supported:
  - Release (optimization, `-DNDEBUG`)
  - Debug (no optimization `-D_DEBUG`)
  - DebugPython (no optimization, `-D_DEBUG -DBOOST_DEBUG_PYTHON`)

  When extension modules are built with Visual C++ using `-D_DEBUG`, Python defaults to force linking with a special debugging version of the Python DLL. Since this debug DLL isn't supplied with the default Python installation for Windows, Boost.Python uses `boost/python/detail/wrap_python.hpp` to temporarily undefine `_DEBUG` when `Python.h` is `#include`d.

  If you want the extra runtime checks available with the debugging version of the library, `#define BOOST_DEBUG_PYTHON` to re-enable library forcing, and link with the DebugPython version of `boost_python.lib`. You'll need to get the debugging version of the Python executable (`python_d.exe`) and DLL (`python20_d.dll` or `python15_d.dll`). The Python sources include project files for building these. If you download them, change the name of the top-level directory to `src`, and install it under `c:\tools\python`, the workspace supplied by Boost.Python will be able to use it without modification. Just open `c:\tools\python\src\pcbuild\pcbuild.dsw` and invoke "build all" to generate all the debugging targets.

  If you do not `#define BOOST_DEBUG_PYTHON`, be sure that any source files `#include <boost/python/detail/wrap_python.hpp>` instead of the usual `Python.h`, or you will have link incompatibilities.

- The makefiles and Visual Studio project can all build at least the following:
  - The `boost_python` library for static linking with your extension module. On the various Unices, this library will be called `libboost_python.a`. On Win32 platforms, the library will be called `boost_python.lib`.
  - A comprehensive test of Boost.Python features. This test builds a Boost.Python extension module, then runs Python to import the module, and runs a series of tests on it using `doctest`. Source code for the module and tests is available in the Boost subdirectory `libs/python/test`.
  - Various examples from the Boost subdirectory `libs/python/example`. Which examples are built currently depends on the platform. The most up-to-date examples are `getting_started` n`.cpp` from Ralf W. Grosse-Kunstleve. All these examples include a doctest modeled on the comprehensive test above.
- If your platform isn't directly supported, you can build a static library from the following source files (in the Boost subdirectory `libs/python/src`), or compile them directly and link the resulting objects into your extension module:
  - extension_class.cpp
  - functions.cpp
  - init_function.cpp
  - module_builder.cpp
  - types.cpp
  - objects.cpp
  - conversions.cpp
  - classes.cpp

Next: Wrapping Enums Previous: A Peek Under the Hood Up: Top

© Copyright David Abrahams 2000. Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document is provided ``as is'' without express or implied warranty, and with no claim as to its suitability for any purpose.

Updated: Mar 6, 2001