SWIG reads annotated C/C++ headers and emits glue code so libraries can be called from Perl, Python, Java, Go, and numerous other languages.
Overview
SWIG (Simplified Wrapper and Interface Generator) connects C and C++ code to high-level languages. It parses annotated header files and produces wrapper code that exposes native libraries to scripting and compiled targets, or lets C/C++ programs embed a scripting language.
Supported targets include Perl, Python, Tcl, Ruby, PHP, Java, C#, D, Go, Lua, Octave, R, JavaScript variants, and more. SWIG can also export its parse tree as XML. Generated wrapper code is usable in both commercial and non-commercial projects.
Typical uses include building interpreted bindings, user interfaces on top of C/C++ cores, and rapid prototyping against existing native libraries. Documentation is provided as PDF, single-page HTML, and multi-page HTML manuals, with additional material online.
Installation instructions cover Windows, Unix, and Mac OS X from release archives or source. The swig command-line tool relies on bundled library files installed with the package.
Key features
- Annotated C/C++ header parsing
- Multi-language wrapper generation
- XML parse tree export
- Scripting and compiled language targets
- Online and offline documentation
- Examples for common language pairs
- Preprocessor and typemap customization
- Backwards compatibility tracking
Use cases
- Python or Java bindings to C++ libraries
- Embedding scripts in C/C++ applications
- Prototyping native code via interpreters
- Exposing legacy C APIs to modern languages