Executive Summary

Executive Summary

SWIG is an interface compiler that connects programs written in C and C++ with scripting languages including Perl, Python, and Tcl/Tk. It works by taking the declarations commonly found in C/C++ header files and using them to generate the glue code (wrappers) that scripting languages need to access the underlying C/C++ code.

John Ousterhout has written a paper that describes the benefits of scripting languages. SWIG makes it fairly easy to connect scripting languages with C/C++ code.

You might use SWIG in a number of ways:

SWIG is sometimes compared to interface definition language (IDL) compilers such as those you would find with systems such as CORBA and COM. Although there are a few similarities, the whole point of SWIG is to make it so you don't have to add an extra layer of IDL specifications to your application. If anything, it's much more of a rapid application development and prototyping tool. Specifically:

It is also worth noting that even though SWIG is occasionally compared to other more specialized scripting language extension building tools (e.g., Perl XS, Python bgen, etc.), its primary audience is C/C++ programmers who want to add a scripting language component to their applications. Because of this, SWIG tends to have a slightly different focus than tools designed to build small modules for widespread use in a scripting language distribution. By far, the most significant difference between SWIG and similar tools is that SWIG implements the full C++ type system--with support for all C datatypes, C++ classes, namespaces, and templates. By focusing on types, SWIG is able to provide a high degree of reliability and it is able to handle the wrapping of large-scale C/C++ code that appears in real applications.

A number of papers and tutorials describing SWIG are available. You can also view a simple tutorial to see an example of SWIG in action, or check out how other people are using SWIG in their projects.

SWIG has been freely available in various forms since February, 1996 and a large number of developers have made contributions. Today, SWIG remains an all-volunteer effort. Approximately 750 people subscribe to the SWIG mailing list (swig@cs.uchicago.edu) and a public CVS repository is available at the University of Chicago. Over 12000 people downloaded the last SWIG release (SWIG-1.3.11).