LinuxCommandLibrary

swig

Generate language bindings for C/C++ code

TLDR

Generate Python wrapper

$ swig -python [interface.i]
copy
Generate with C++
$ swig -c++ -python [interface.i]
copy
Specify output file
$ swig -python -o [wrap.c] [interface.i]
copy
Include directory
$ swig -I[/usr/include] -python [interface.i]
copy
Generate Java wrapper
$ swig -java [interface.i]
copy

SYNOPSIS

swig [-python|-java|-ruby] [-c++] [-o file] [options] interface.i

DESCRIPTION

swig (Simplified Wrapper and Interface Generator) generates wrapper code that allows C and C++ libraries to be called from other programming languages. It reads interface definition files (.i) that describe which functions, classes, and types to expose, and produces the glue code needed for the target language.
Supported target languages include Python, Java, Ruby, Perl, PHP, Lua, Go, JavaScript, C#, and many others. SWIG handles automatic type conversion and data marshaling between C/C++ and the target language, including complex types, pointers, arrays, and object-oriented constructs like inheritance and templates.
Interface files use a syntax similar to C/C++ header files with additional SWIG directives for controlling the wrapping process. SWIG can also parse actual C/C++ header files directly for simpler cases.

PARAMETERS

-python

Python target.
-java
Java target.
-ruby
Ruby target.
-c++
C++ mode.
-o FILE
Output file.
-I DIR
Include path.
-module NAME
Module name.

CAVEATS

Learning curve for interface files. C/C++ knowledge needed. Build system integration.

HISTORY

SWIG (Simplified Wrapper and Interface Generator) was created by David Beazley for connecting C/C++ with scripting languages.

SEE ALSO

cython(1), pybind11(1), ctypes(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community