Section: User Commands (1)
Updated: March 2021
Page Index


swig - Simplified Wrapper and Interface Generator  


swig [ options ] " file"  


The swig command is used to create wrapper code to connect C and C++ code to scripting languages like Perl, Python, Tcl etc. from the definition of the interface. For detailed information on writing those interface definitions please refer to /usr/share/doc/swig-doc/Doc/Manual/index.html from the swig-doc package.

This manpage concentrates on explaining the invocation of the swig command.  


Supported Target Language Options
Generate C# wrappers
Generate D wrappers
Generate Go wrappers
Generate Guile wrappers
Generate Java wrappers
Generate Javascript wrappers
Generate Lua wrappers
Generate Octave wrappers
Generate Perl 5 wrappers
Generate PHP 7 wrappers
Generate Python wrappers
Generate R (aka GNU S) wrappers
Generate Ruby wrappers
Generate Scilab wrappers
Generate Tcl 8 wrappers
Generate XML wrappers

Experimental Target Language Options

Generate MzScheme/Racket wrappers
Generate OCaml wrappers

General Options

Add extra extern declarations
Enable C++ processing
-co <file>
Check <file> out of the SWIG library
Automatically generate copy constructors wherever possible
Treat the preprocessor #error statement as #warning (default)
-cppext <ext>
Change file extension of generated C++ files to <ext> (default is cxx)
Display copyright notices
Display information about the classes found in the interface
-debug-module <n> Display module parse tree at stages 1-4, <n> is a csv list of stages
Display symbol tables information
Display target language symbols in the symbol tables
Display C symbols in the symbol tables
Display target language layer symbols
Display information about the tags found in the interface
Display information for debugging templates
-debug-top <n>
Display entire parse tree at stages 1-4, <n> is a csv list of stages
Display information about the types and typedefs in the interface
Display typemap debugging information
Display typemap search debugging information
Display typemaps used debugging information
Turn on director mode for all the classes, mainly for testing
Turn on wrapping of protected members for director classes (default)
Define a symbol <symbol> (for conditional compilation)
Preprocess only, does not generate wrapper code
-external-runtime [file]
Export the SWIG runtime stack
-fakeversion <v> Make SWIG fake the program version number to <v>
Compile in compact mode
-features <list> Set global features, where <list> is a comma separated list of
features, eg -features directors,autodoc=1 If no explicit value is given to the feature, a default of 1 is used
Enable fast dispatch mode to produce faster overload dispatcher code
Display error/warning messages in Microsoft format
Display error/warning messages in commonly used format
Compile in virtual elimination mode
Display help
-I - Don't search the current directory
Look for SWIG files in directory <dir>
Ignore missing include files
Follow all #include statements as imports
Follow all #include statements
Include SWIG library file <ifile>
Report errors inside macros
Create default constructors/destructors (the default)
List all dependencies
Is equivalent to `-M -MF <file>', except `-E' is not implied
-MF <file>
Generate dependencies into <file> and continue generating wrappers
List dependencies, but omit files in SWIG library
Like `-MD', but omit files in SWIG library
-module <name>
Set module name to <name>
Generate phony targets for all dependencies
-MT <target>
Set the target of the rule emitted by dependency generation
Turn off contract checking
Do not treat the preprocessor #error statement as #warning
Do not generate default constructors nor default destructors
Do not generate implicit default constructors
Do not generate implicit default destructors
Do not wrap director protected members
Do not wrap exception specifiers
Disable fast dispatch mode (default)
Skip the preprocessor step
Disable reduction of the typedefs in templates
Enable the optimization options: -fastdispatch -fvirtual
-o <outfile>
Set name of C/C++ output file to <outfile>
-oh <headfile>
Set name of C++ output header file for directors to <headfile>
Set default output dir to current dir instead of input file's path
-outdir <dir>
Set language specific files output directory to <dir>
Display PCRE version information
Compile in virtual elimination and compact mode
Report location of SWIG library and exit
Reduce all the typedefs in templates
Run in verbose mode
Display SWIG version number
Remove all warning suppression, also implies -Wextra
Enable keyword warnings for all the supported languages
Treat warnings as errors
Adds the following additional warnings: 202,309,403,405,512,321,322
Suppress/add warning messages, eg -w401,+321 - see Warnings.html
-xmlout <file>
Write XML version of the parse tree to <file> after normal processing

Options can also be defined using the SWIG_FEATURES environment variable, for example:

$ swig -python interface.i

is equivalent to:

$ swig -Wall -python interface.i

Arguments may also be passed in a file, separated by whitespace. For example:

$ echo "-Wall -python interface.i" > args.txt
$ swig @args.txt

Note: 'swig -<lang> -help' displays options for a specific target language.  


SWIG was originally created by David Beazley. For up-to-date information about authors and contributors please check http://www.swig.org/guilty.html. This manual page was written by Torsten Landschoff <torsten@debian.org> and updated by Jitka Plesnikova <jplesnik@redhat.com> (but may be used by others).