• DocumentCode
    1155503
  • Title

    Using SWIG to bind C++ to Python

  • Author

    Cottom, T.L.

  • Author_Institution
    Lawrence Livermore Nat. Lab., CA, USA
  • Volume
    5
  • Issue
    2
  • fYear
    2003
  • Firstpage
    88
  • Lastpage
    97
  • Abstract
    An increasingly popular approach to scientific computing is to combine Python and compiled modules. Such an approach merges the high performance typically found in compiled routines with the interface of a flexible, scalable, and easy-to-learn interpreted language. Although using C to hand-code extensions to Python binds the latter to a given compiled asset in C++, programmers who used C++´s more advanced features (until recently) lacked the automated support available in Fortran and C. One tool for creating Python bindings to C the Simplified Wrapper and Interface Generator. SWIG-an open-source application used by a large and ever-expanding community-began as an effort to expose physics packages in a large parallel simulation code to interpreted languages. SWIG preprocesses C and C++ code and generates library bindings in several interpreted languages including Python, Pert, Tcl, and Java. Recent improvements to SWIG provide greater support for binding C++ code. SWIG now creates, for example, bindings for some of C++´s more advanced features such as templates and exceptions. This article explores how SWIG does this by examining a series of small C++ code examples.
  • Keywords
    C++ language; application program interfaces; object-oriented programming; physics computing; C code preprocessing; C++ code preprocessing; C++/Python binding; Java; Perl; SWIG; Simplified Wrapper and Interface Generator; Tcl; exceptions; interpreted languages; large parallel simulation code; library bindings; open-source application; physics packages; templates; Libraries; Linux; Prototypes; Scientific computing;
  • fLanguage
    English
  • Journal_Title
    Computing in Science & Engineering
  • Publisher
    ieee
  • ISSN
    1521-9615
  • Type

    jour

  • DOI
    10.1109/MCISE.2003.1182968
  • Filename
    1182968