SWIG (Simplified Wrapper and Interface Generator)
Version: 2.0.2 (20 February 2011)
Tagline: SWIG is a compiler that integrates C and C++ with languages
including Perl, Python, Tcl, Ruby, PHP, Java, Ocaml, Lua,
Scheme (Guile, MzScheme, CHICKEN), Pike, C#, Modula-3,
Common Lisp (CLISP, Allegro CL, CFFI, UFFI), Octave and R.
SWIG reads annotated C/C++ header files and creates wrapper code (glue
code) in order to make the corresponding C/C++ libraries available to
the listed languages, or to extend C/C++ programs with a scripting
Up-to-date SWIG related information can be found at
A SWIG FAQ and other hints can be found on the SWIG Wiki:
Please see the LICENSE file for details of the SWIG license.
Please see the CHANGES.current file for a detailed list of bug fixes and
new features for the current release. The CHANGES file contains bug fixes
and new features for older versions. A summary of changes in each release
can be found in the RELEASENOTES file.
The developers strive their best to preserve backwards compatibility
between releases, but this is not always possible as the overriding
aim is to provide the best wrapping experience. Where backwards
compatibility is known to be broken, it is clearly marked as an
incompatibility in the CHANGES and CHANGES.current files.
See the documentation for details of the SWIG_VERSION preprocessor
symbol if you have backward compatibility issues and need to use more
than one version of SWIG.
Please see the Doc/Manual/Windows.html file for instructions on installing
SWIG on Windows and running the examples. The Windows distribution is
called swigwin and includes a prebuilt SWIG executable, swig.exe, included in
the same directory as this README file. Otherwise it is exactly the same as
the main SWIG distribution. There is no need to download anything else.
You must use GNU `make' to build SWIG.
PCRE needs to be installed on your system to build SWIG. The configure
script will provide instructions for obtaining PCRE if it cannot be found.
To build and install SWIG, simply type the following:
% make install
By default SWIG installs itself in /usr/local. If you need to install SWIG in
a different location or in your home directory, use the --prefix option
to ./configure. For example:
% ./configure --prefix=/home/yourname/projects
% make install
Note: the directory given to --prefix must be an absolute pathname. Do *NOT* use
the ~ shell-escape to refer to your home directory. SWIG won't work properly
if you do this.
The file INSTALL details more about using configure. Also try
% ./configure --help.
The configure script will attempt to locate various packages on your machine
including Tcl, Perl5, Python and all the other target languages that SWIG
uses. Don't panic if you get 'not found' messages--SWIG does not need these
packages to compile or run. The configure script is actually looking for
these packages so that you can try out the SWIG examples contained
in the 'Examples' directory without having to hack Makefiles.
Note that the --without-xxx options, where xxx is a target language, have
minimal effect. All they do is reduce the amount of testing done with
'make check'. The SWIG executable and library files installed cannot currently
be configured with a subset of target languages.
Please see the Documentation section below on installing documentation as
none is installed by default.
SWIG used to include a set of runtime libraries for some languages for working
with multiple modules. These are no longer built during the installation stage.
However, users can build them just like any wrapper module as described in
the documentation, Doc/Manual/Modules.html. The CHANGES file also lists some
examples which build the runtime library.
(1) If you checked the code out via SVN, you will have to run ./autogen.sh
before typing 'configure'. In addition, a full build of SWIG requires
the a number of packages to be installed. Full instructions at
Macintosh OS X Installation
SWIG is known to work on various flavors of OS X. Follow the Unix installation
instructions above. However, as of this writing, there is still great deal of
inconsistency with how shared libaries are handled by various scripting languages
on OS X. We've tried to resolve these differences to the extent of our knowledge.
Users of OS X should be aware that Darwin handles shared libraries and linking in
a radically different way than most Unix systems. In order to test SWIG and run
the examples, SWIG configures itself to use flat namespaces and to allow undefined
symbols (-flat_namespace -undefined suppress). This mostly closely follows the Unix
model and makes it more likely that the SWIG examples will work with whatever
installation of software you might have. However, this is generally not the recommended
technique for building larger extension modules. Instead, you should utilize
Darwin's two-level namespaces. Some details about this can be found here
Needless to say, you might have to experiment a bit to get things working at first.
If you want to test SWIG before installation, type the following:
% make -k check
'make -k check' requires at least one of the target languages to be
installed. If it fails, it may mean that you have an uninstalled
language module or that the file 'Examples/Makefile' has been
incorrectly configured. It may also fail due to compiler issues such
as broken C++ compiler. Even if 'make -k check' fails, there is a
pretty good chance SWIG still works correctly---you will just have to
mess around with one of the examples and some makefiles to get it to work.
Some tests may also fail due to missing dependency packages, eg PCRE
or Boost, but this will require careful analysis of the configure output.
The testing suite executed by 'make -k check' is designed to stress-test
many parts of the implementation including obscure corner cases. If some
of these tests fail or generate warning messages, there is no reason for
alarm---the test may be related to some new SWIG feature or a difficult bug
that we're trying to resolve. Chances are that SWIG will work just fine
for you. Note that if you have more than one CPU/core, then you can use
parallel make to speed up the check as it does take quite some time to run,
% make -j2 -k check
Also, SWIG's support for C++ is sufficiently advanced that certain
tests may fail on older C++ compilers (for instance if your compiler
does not support member templates). These errors are harmless if you
don't intend to use these features in your own programs.
Note: The test-suite currently contains over 500 tests. If you
have many different target languages installed and a slow machine, it
might take more than an hour to run the test-suite.
The Examples directory contains a variety of examples of using SWIG
and it has some browsable documentation. Simply point your browser to
the file "Example/index.html".
The Examples directory also includes Visual C++ project (.dsp) files for
building some of the examples on Windows.
There are minor known bugs, details of which are in the bug tracker, see
In order to operate correctly, SWIG relies upon a set of library
files. If after building SWIG, you get error messages like this,
% swig foo.i
:1. Unable to find 'swig.swg'
:3. Unable to find 'tcl8.swg'
it means that SWIG has either been incorrectly configured or
installed. To fix this:
1. Make sure you remembered to do a 'make install' and that
the installation actually worked. Make sure you have
write permission on the install directory.
2. If that doesn't work, type 'swig -swiglib' to find out
where SWIG thinks its library is located.
3. If the location is not where you expect, perhaps
you supplied a bad option to configure. Use
./configure --prefix=pathname to set the SWIG install
location. Also, make sure you don't include a shell
escape character such as ~ when you specify the path.
4. The SWIG library can be changed by setting the SWIG_LIB
environment variable. However, you really shouldn't
have to do this.
If you are having other troubles, you might look at the SWIG Wiki at
The Doc/Manual directory contains the most recent set of updated
documentation for this release. The documentation is available in
three different formats, each of which contains identical content.
These format are, pdf (Doc/Manual/SWIGDocumentation.pdf), single
page html (Doc/Manual/SWIGDocumentation.html) or multiple page html
(other files in Doc/Manual). Please select your chosen format and
copy/install to wherever takes your fancy.
There is some technical developer documentation available in the
Doc/Devel subdirectory. This is not necessarily up-to-date, but it
has some information on SWIG internals.
Please report any errors and submit patches (if possible)! We only
have access to a limited variety of hardware (Linux, Solaris, OS-X,
and Windows). All contributions help.
If you would like to join the SWIG development team or contribute a
language module to the distribution, please contact the swig-devel
mailing list, details at http://www.swig.org/mail.html.
-- The SWIG Maintainers
This file contains the changes for the current release.
See the CHANGES file for changes in older releases.
See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.2 (20 February 2011)
[PHP] Add missing INPUT, OUTPUT and INOUT typemaps in the typemaps.i library
for primitive reference types as well as signed char * and bool *.
[PHP] Address bug in PHP on some platforms/architectures which
results in zend_error_noreturn() not being available using
SWIG_ZEND_ERROR_NORETURN which defaults to zend_error_noreturn but
can be overridden when building the module by passing
-DSWIG_ZEND_ERROR_NORETURN=zend_error to the compiler. This may
result in compiler warnings, but should at least allow a module
to be built on those platforms/architectures (SF#3166423).
Fix #3184549 - vararg functions and function overloading when using the -fastdispatch option.
[PHP] An overloaded method which can return an object or a
primitive type no longer causes SWIG to segfault. Reported by Paul
Colby in SF#3168531.
[PHP] Fix invalid erase during iteration of std::map in generated
director code. Reported by Cory Bennett in SF#3175820.
Preprocessing now warns if extra tokens appear after #else and #end.
Fix #1653092 Preprocessor does not error out when #elif is missing an expression.
This and other cases of missing preprocessor expressions now result in an error.
[Ocaml] Apply patch #3151788 from Joel Reymont. Brings Ocaml support up to date
(ver 3.11 and 3.12), including std::string.
[Ruby] Apply patch #3176274 from James Masters - typecheck typemap for time_t.
Apply patch #3171793 from szager - protected director methods failing when -fvirtual is used.
Fix #1927852 - #include directives don't preprocess the file passed to it. The fix is for
#include with -importall or -includeall, %include and %import, for example:
#define FILENAME "abc.h"
Fix #1940536, overactive preprocessor which was expanding defined(...) outside of #if and #elif
[MzScheme] SF #2942899 Add user supplied documentation to help getting started with MzScheme.
Update chapter name to MzScheme/Racket accounting for the rename of MzScheme to Racket.
[C#] SF #3085906 - Possible fix running test-suite on Mac OSX.
SF #3173367 Better information during configure about Boost prerequisite for running
SF #3127633 Fix infinite loop in recursive typedef resolution.
[R] SF #3168676 Fix %rename not working for member variables and methods.
[clisp] SF #3148200 Fix segfault parsing nested unions.
[C#] Directors - a call to a method being defined in the base class, not
overridden in a subclass, but again overridden in a class derived from
the first subclass was not being dispatched correctly to the most derived class.
See director_alternating.i for an example.
[C#, Java] Any 'using' statements in the protected section of a class were previously
ignored with director protected (dirprot) mode.
Fix overloading with const pointer reference (SWIGTYPE *const&) parameters for a
number of scripting languages.
New warning for smart pointers if only some of the classes in the inheritance
chain are marked as smart pointer, eg, %shared_ptr should be used for all classes
in an inheritance hierarchy, so this new warning highlights code where this is
not the case.
example.i:12: Warning 520: Base class 'A' of 'B' is not similarly marked as a smart pointer.
example.i:16: Warning 520: Derived class 'C' of 'B' is not similarly marked as a smart pointer.
Added some missing multi-argument typemaps: (char *STRING, size_t LENGTH) and
(char *STRING, int LENGTH). Documentation for this updated. Java patch from
Require Go version 7077 or later.
[C#, D, Java] Check for collision of parameter names with target
language keywords when generating the director glue code.
The situation in which the generated could would previously be
invalid is illustrated in the new 'director_keywords' test case.
[C#] Fix $csinput special variable not being expanded for csvarin typemaps
when used for global variables. Reported by Vadim Zeitlin.
Fix $basemangle expansion in array typemaps. For example if type is int *,
$basemangle expands to _p_int.
Check that we are using a sufficiently new version of the
6g or 8g Go compiler during configure time. If not, disable Go.
Minimum version is now 6707.
*** POTENTIAL INCOMPATIBILITY ***
Fix #3127394 - use of network paths on Windows/MSys.
[D] Added the D language module.
Fix handling of multiple regex-using %renames attached to the same
declaration. For example, now
works as expected whereas before only the last anonymous rename was
taken into account.
[R] Fix failure in overloaded functions which was breaking
[PHP] Allow compilation on non-conforming Microsoft C++ compilers
which don't accept: return function_returning_void();
Reported by Frank Vanden Berghen on the SWIG mailing list.
Fix unary scope operator (::) (global scope) regression introduced in 2.0.0, reported by
Ben Walker. The mangled symbol names were incorrect, sometimes resulting in types being
incorrectly treated as opaque types.
Also fixes #2958781 and some other type problems due to better typedef resolution, eg
std::vector<T *>::value_type didn't resolve to T * when it should have. The mangled type
was incorrectly SWIGTYPE_std__vectorT_Test_p_std__allocatorT_Test_p_t_t__value_type and now
it is correctly SWIGTYPE_p_Test.
This file contains a brief overview of the changes made in each release.
A detailed description of changes are available in the CHANGES.current
and CHANGES files.
- Support for the D language has been added.
- Various bug fixes and minor enhancements.
- Bug fixes particular to the Clisp, C#, Go, MzScheme, Ocaml, PHP, R,
Ruby target languages.
- Support for the Go language has been added.
- New regular expression (regex) encoder for renaming symbols based on
the Perl Compatible Regular Expressions (PCRE) library.
- Numerous fixes in reporting file and line numbers in error and warning
- Various bug fixes and improvements in the C#, Lua, Perl, PHP, Ruby
and Python language modules.
- License changes, see LICENSE file and http://www.swig.org/legal.html.
- Much better nested class/struct support.
- Much improved template partial specialization and explicit
- Namespace support improved with the 'nspace' feature where namespaces
can be automatically translated into Java packages or C# namespaces.
- Improved typemap and symbol table debugging.
- Numerous subtle typemap matching rule changes when using the default
(SWIGTYPE) type. These now work much like C++ class template partial
- Other small enhancements for typemaps. Typemap fragments are also now
official and documented.
- Warning and error display refinements.
- Wrapping of shared_ptr is improved and documented now.
- Numerous C++ unary scope operator (::) fixes.
- Better support for boolean expressions.
- Various bug fixes and improvements in the Allegrocl, C#, Java, Lua,
Octave, PHP, Python, R, Ruby and XML modules.
- SWIG now supports directors for PHP.
- PHP support improved in general.
- Octave 3.2 support added.
- Various bug fixes/enhancements for Allegrocl, C#, Java, Octave, Perl,
Python, Ruby and Tcl.
- Other generic fixes and minor new features.
- Some new small feature enhancements.
- Improved C# std::vector wrappers.
- Bug fixes: mainly Python, but also Perl, MzScheme, CFFI, Allegrocl
- Output directory regression fix and other minor bug fixes
- Python 3 support added
- SWIG now ships with a version of ccache that can be used with SWIG.
This enables the files generated by SWIG to be cached so that repeated
use of SWIG on unchanged input files speeds up builds quite considerably.
- PHP 4 support removed and PHP support improved in general
- Improved C# array support
- Numerous Allegro CL improvements
- Bug fixes/enhancements for Python, PHP, Java, C#, Chicken, Allegro CL,
CFFI, Ruby, Tcl, Perl, R, Lua.
- Other minor generic bug fixes and enhancements
- Enhancement to directors to wrap all protected members
- Optimisation feature for objects returned by value
- A few bugs fixes in the PHP, Java, Ruby, R, C#, Python, Lua and
- Other minor generic bug fixes
- Octave language module added
- Bug fixes in Python, Lua, Java, C#, Perl modules
- A few other generic bugs and runtime assertions fixed
- shared_ptr support for Python
- Support for latest R - version 2.6
- Various minor improvements/bug fixes for R, Lua, Python, Java, C#
- A few other generic bug fixes, mainly for templates and using statements
- Fix regression for Perl where C++ wrappers would not compile
- Fix regression parsing macros
- shared_ptr support for Java and C#
- Enhanced STL support for Ruby
- Windows support for R
- Fixed long-standing memory leak in PHP Module
- Numerous fixes and minor enhancements for Allegrocl, C#, cffi, Chicken, Guile,
Java, Lua, Ocaml, Perl, PHP, Python, Ruby, Tcl.
- Improved warning support
- Python modern classes regression fix
- Python-2.5 support
- New language module: R
- Director support added for C#
- Numerous director fixes and improvements
- Improved mingw/msys support
- Better constants support in Guile and chicken modules
- Support for generating PHP5 class wrappers
- Important Java premature garbage collection fix
- Minor improvements/fixes in cffi, php, allegrocl, perl, chicken, lua, ruby,
ocaml, python, java, c# and guile language modules
- Many many other bug fixes
- Numerous important bug fixes
- Few minor new features
- Some performance improvements in generated code for Python
- More powerful renaming (%rename) capability.
- More user friendly warning handling.
- Add finer control for default constructors and destructors. We discourage
the use of the 'nodefault' option, which disables both constructors and
destructors, leading to possible memory leaks. Use instead 'nodefaultctor'
- Automatic copy constructor wrapper generation via the 'copyctor' option/feature.
- Better handling of Windows extensions and types.
- Better runtime error reporting.
- Add the %catches directive to catch and dispatch exceptions.
- Add the %naturalvar directive for more 'natural' variable wrapping.
- Better default handling of std::string variables using the %naturalvar directive.
- Add the %allowexcept and %exceptionvar directives to handle exceptions when
accessing a variable.
- Add the %delobject directive to mark methods that act like destructors.
- Add the -fastdispatch option to enable smaller and faster overload dispatch
- Template support for %rename, %feature and %typemap improved.
- Add/doc more debug options, such as -dump_module, -debug_typemaps, etc.
- Unified typemap library (UTL) potentially providing core typemaps for all
scripting languages based on the recently evolving Python typemaps.
- New language module: Common Lisp with CFFI.
- Python, Ruby, Perl and Tcl use the new UTL, many old reported and hidden
errors with typemaps are now fixed.
- Initial Java support for languages using the UTL via GCJ, you can now use
Java libraries in your favorite script language using gcj + swig.
- Tcl support for std::wstring.
- PHP4 module update, many error fixes and actively maintained again.
- Allegrocl support for C++, also enhanced C support.
- Ruby support for bang methods.
- Ruby support for user classes as native exceptions.
- Perl improved dispatching in overloaded functions via the new cast and rank
- Perl improved backward compatibility, 5.004 and later tested and working.
- Python improved backward compatibility, 1.5.2 and later tested and working.
- Python can use the same cast/rank mechanism via the -castmode option.
- Python implicit conversion mechanism similar to C++, via the %implicitconv
directive (replaces and improves the implicit.i library).
- Python threading support added.
- Python STL support improved, iterators are supported and STL containers can
use now the native PyObject type.
- Python many performance options and improvements, try the -O option to test
all of them. Python runtime benchmarks show up to 20 times better performance
compared to 1.3.27 and older versions.
- Python support for 'multi-inheritance' on the python side.
- Python simplified proxy classes, now swig doesn't need to generate the
additional 'ClassPtr' classes.
- Python extended support for smart pointers.
- Python better support for static member variables.
- Python backward compatibility improved, many projects that used to work
only with swig-1.3.21 to swig-1.3.24 are working again with swig-1.3.28
- Python test-suite is now 'valgrinded' before release, and swig also
reports memory leaks due to missing destructors.
- Minor bug fixes and improvements to the Lua, Ruby, Java, C#, Python, Guile,
Chicken, Tcl and Perl modules.
- Fix bug in anonymous typedef structures which was leading to strange behaviour
- New language modules: Lua, CLISP and Common Lisp with UFFI.
- Big overhaul to the PHP module.
- Change to the way 'extern' is handled.
- Minor bug fixes specific to C#, Java, Modula3, Ocaml, Allegro CL,
XML, Lisp s-expressions, Tcl, Ruby and Python modules.
- Other minor improvements and bug fixes.
- Improved runtime type system. Speed of module loading improved in
modules with lots of types. SWIG_RUNTIME_VERSION has been increased
from 1 to 2, but the API is exactly the same; only internal changes
- The languages that use the runtime type system now support external
access to the runtime type system.
- Various improvements with typemaps and template handling.
- Fewer warnings in generated code.
- Improved colour documentation.
- Many C# module improvements (exception handling, prevention of early
garbage collection, C# attributes support added, more flexible type
- Minor improvements and bug fixes specific to the C#, Java, TCL, Guile,
Chicken, MzScheme, Perl, Php, Python, Ruby and Ocaml modules).
- Various other bug fixes and memory leak fixes.
- Improved enum handling
- More runtime library options
- More bugs fixes for templates and template default arguments, directors
and other areas.
- Better smart pointer support, including data members, static members
- Improved support for callbacks
- Python docstring support and better error handling
- C++ default argument support for Java and C# added.
- Improved c++ default argument support for the scripting languages plus
option to use original (compact) default arguments.
- %feature and %ignore/%rename bug fixes and mods - they might need default
arguments specified to maintain compatible behaviour when using the new
default arguments wrapping.
- Runtime library changes: Runtime code can now exist in more than one module
and so need not be compiled into just one module
- Further improved support for templates and namespaces
- Overloaded templated function support added
- More powerful default typemaps (mixed default typemaps)
- Some important %extend and director code bug fixes
- Guile now defaults to using SCM API. The old interface can be obtained by
the -gh option.
- Various minor improvements and bug fixes for C#, Chicken, Guile, Java,
MzScheme, Perl, Python and Ruby
- Improved dependencies generation for constructing Makefiles.
- Improved exception handling and translation of C errors or C++
exceptions into target language exceptions.
- Improved enum support, mapping to built-in Java 1.5 enums and C#
enums or the typesafe enum pattern for these two languages.
- Python - much better STL suppport and support for std::wstring,
wchar_t and FILE *.
- Initial support for Modula3 and Allegro CL.
- 64 bit TCL support.
- Java and C#'s proxy classes are now nearly 100% generated from
typemaps and/or features for finer control on the generated code.
- SWIG runtime library support deprecation.
- Improved documentation. SWIG now additionally provides documentation
in the form of a single HTML page as well as a pdf document.
- Enhanced C++ friend declaration support.
- Better support for reference counted classes.
- Various %fragment improvements.
- RPM fixes.
- Various minor improvements and bug fixes for C#, Chicken, Guile, Java,
MzScheme, Perl, Php, Python, Ruby and XML.