LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

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.

INSTALL

sudo apt install swig
copy
sudo dnf install swig
copy
sudo pacman -S swig
copy
sudo apk add swig
copy
sudo zypper install swig
copy
brew install swig
copy
nix profile install nixpkgs#swig
copy

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)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid