Building SWIG Python Extensions on GNU/Linux

Originally published: May 27, 2005

Table of Contents

  1. Abstract
  2. Building Manually on the Command Line
  3. Adding SWIG to Autoconf
  4. Adding SWIG to Automake
  5. An Example Project

Abstract

In the article Python Extensions In C++ Using SWIG, I describe how to extend Python with C++ code. That article also contains instructions for building SWIG extension DLLs on Windows. This article contains instructions for using GNU Automake and Autoconf to build SWIG extensions as shared objects on GNU/Linux.

. . . → Read More

Python Extensions In C++ Using SWIG

Originally published: Oct 8, 2003 (Last update: August 15, 2007)

Table of Contents

  1. Abstract
  2. Introduction
  3. The Python/C API
  4. SWIG Basics
    1. A Quick Example
  5. Building Extensions on GNU/Linux
  6. Building Extensions on Windows
    1. Setting Up The Environment
    2. Enabling Syntax-Highlighting For .i Files
    3. Setting Up The DLL Project
    4. SWIG As A Custom Build Step
    5. Troubleshooting
  7. A Case Study: “pymfg”
    1. Namespaces And Other Reasons Why Your Classes Aren’t Wrapped
    2. Hiding The Unwanted And Faking The Non-Existent
    3. Someone Has Done All The Work – Using STL Classes
    4. The Problem With Pointers To Pointers
  8. Conclusion

Abstract

This article walks you through the process of writing a Python extension module in C++. To simplify the task, we are going to use SWIG to produce the “glue code” between Python and C++. The article presents the following concepts:

  • Converting between C++ and Python data types
  • Setting up an extension module project that uses SWIG
  • Using SWIG interface definition files
  • Exporting functions and classes
  • Exporting STL containers

. . . → Read More

My Buzz