SWIG
| Original author(s) | Dave Beazley |
|---|---|
| Developer(s) | SWIG developers |
| Initial release | February 1996[1] |
| Stable release | 2.0.4 / May 21, 2011 |
| Written in | C, C++ |
| Operating system | Cross-platform |
| License | GPL |
| Website | swig.org |
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, Modula-3, Objective Caml, Octave, and Scheme. Output can also be in the form of XML or Lisp S-expressions.
Contents |
[edit] Function
The aim is to allow calling native functions (C or C++) by interpreted code, passing complex data types, keeping memory from being freed, inheriting classes across languages etc. The programmer writes an interface file containing a list of C/C++ functions to be visible to an interpreter. SWIG will compile the interface file into a regular C/C++. SWIG will generate conversion code for functions with simple arguments; conversion code for complex types of arguments has to be written by programmer. SWIG tool creates source code which 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 has to be done by the programmer manually.
[edit] Purpose
There are two main reasons to embed a scripting engine in an extant 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++.
- Unit testing of C or C++ code is often better done from a scripting language.
[edit] History
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.
[edit] Concurrents
For Python, similar functionality is offered by SIP and Boost's Boost.python library
[edit] See also
- Language binding
- Foreign function interface
- Calling convention
- Name mangling
- Application programming interface - API
- Application Binary Interface - ABI
- Comparison of application virtual machines
- Wrapper function
[edit] References
[edit] Projects Using SWIG
- ZXID (Apache2 open source)
- Symlabs SFIS (commercial)
- etc. Many other projects use SWIG. Please add them here.
[edit] External links
- Official website
- Project home page at SourceForge
- SwigWiki, Wiki with information on using SWIG
- 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
- Citations from CiteSeer