World Library  
Flag as Inappropriate
Email this Article


Original author(s) Dave Beazley
Developer(s) SWIG developers
Initial release February 1996[1]
Stable release 3.0.7 / August 3, 2015 (2015-08-03)
Written in C, C++
Operating system Cross-platform
License GPL
Website .orgswig

SWIG (Simplified Wrapper and Interface Generator) is an open source software tool used to connect computer programs or libraries written in C or C++ with scripting languages such as Lua, Perl, PHP, Python, R, Ruby, Tcl, and other languages like C#, Java, JavaScript, Go, Modula-3, OCaml, Octave, Scilab and Scheme. Output can also be in the form of XML or Lisp S-expressions.


  • Function 1
  • Purpose 2
  • History 3
  • Google Summer of Code 4
  • Concurrents 5
  • Projects Using SWIG 6
  • See also 7
  • References 8
  • Further reading 9
  • External links 10


The aim is to allow the calling of native functions (that were written in C or C++) by other programming languages, passing complex data types to those functions, keeping memory from being inappropriately freed, inheriting object classes across languages, etc. The programmer writes an interface file containing a list of C/C++ functions to be made visible to an interpreter. SWIG will compile the interface file and generate regular C/C++ as well as code in the target programming language. SWIG will generate conversion code for functions with simple arguments; conversion code for complex types of arguments must be written by the programmer. The SWIG tool creates source code that provides the glue between C/C++ and the target language. Depending on the language, this glue comes in two forms:

  • a shared library that an extant interpreter can link to as some form of extension module, or
  • a shared library that can be linked to other programs compiled in the target language (for example, using JNI in Java).

SWIG is not used for calling interpreted functions by native code; this must be done by the programmer manually.


There are two main reasons to embed a scripting engine in an existing C/C++ program:

  • The program can then be customized far faster, via a scripting language instead of C/C++. The scripting engine may even be exposed to the end user, so that they can automate common tasks by writing scripts.
  • Even if the final product is not to contain the scripting engine, it may nevertheless be very useful for writing test scripts.

There are several reasons to create dynamic libraries that can be loaded into extant interpreters, including:

  • Provide access to a C/C++ library which has no equivalent in the scripting language.
  • Write the whole program in the scripting language first, and after profiling, rewrite performance critical code in C or C++.


SWIG is written in C and C++ and has been publicly available since February 1996. The initial author and main developer was Dave Beazley who developed SWIG while working as a graduate student at Los Alamos National Laboratory and the University of Utah and while on the faculty at the University of Chicago. Development is currently supported by an active group of volunteers led by William Fulton. SWIG has been released under a GNU General Public License.

Google Summer of Code

SWIG was a successful participant of Google Summer of Code in 2008, 2009, 2012. In 2008, SWIG got four slots. Haoyu Bai spent his summers on SWIG's Python 3.0 Backend, Jan Jezabek worked on Support for generating COM wrappers, Cheryl Foil spent her time on Comment 'Translator' for SWIG, and Maciej Drwal worked on a C backend. In 2009, SWIG again participated in Google Summer of Code. This time four students participated. Baozeng Ding worked on a Scilab module. Matevz Jekovec spent time on C++0x features. Ashish Sharma spent his summer on an Objective-C module, Miklos Vajna spent his time on PHP directors.

In 2012, SWIG participated in Google Summer of Code. This time four out of five students successfully completed the project. Leif Middelschulte worked on a C target language module. Swati Sharma enhanced the Objective-C module. Neha Narang added the new module on JavaScript. Dmitry Kabak worked on source code documentation and Doxygen comments.


For Python, similar functionality is offered by SIP and Boost's Boost.python library.

Projects Using SWIG

See also


  1. ^

Further reading

  • Article "Expose Your C/C++ Program's Internal API with a Quick SWIG" by Victor Volkman
  • Article "Python Extensions In C++ Using SWIG" by Michael Fötsch
  • Presentation "Application overview for openSUSE" by Klaus Kämpf

External links

  • Official website
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.