Introduction to SWIG

SWIG (Simplified Wrapper and Interface Generator) is a compiler that integrates C and C++ with languages including Perl, Python, Tcl, Ruby, PHP, Java, C#, D, Go, Lua, Octave, R, Scheme, Ocaml, Modula-3, Common Lisp, and Pike. SWIG can also export its parse tree into Lisp s-expressions and XML.

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 language.

This package is known to build and work properly using an LFS-7.6 platform.

Package Information

  • Download (HTTP): http://downloads.sourceforge.net/swig/swig-3.0.4.tar.gz

  • Download MD5 sum: 9cb8c0efda39dc6db5f85389e671fb59

  • Download size: 5.45 MB

  • Estimated disk space required: 78 MB (up to 1.1 GB for tests)

  • Estimated build time: 0.4 SBU (22 SBU for tests of Guile, Go, Java, Lua, Perl, PHP, Python 2 and 3, Ruby, and Tcl)

SWIG Dependencies




Boost-1.57.0 for tests, and any of the languages mentionned in the introduction, as run-time dependencies

User Notes: http://wiki.linuxfromscratch.org/blfs/wiki/swig

Installation of SWIG

Fix an issue with gccgo-4.9.2:

sed -i 's/"\.")/"_")/' -i Source/Modules/go.cxx

Install SWIG by running the following commands:

./configure --prefix=/usr   \
            --without-clisp &&

To test the results, issue: make -k check. If you have both Python-2.7.9 and Python-3.4.2 installed, only the Python-2 tests are run. You can run test for Python-3 by issuing PY3=1 make check-python-examples followed by PY3=1 make check-python-test-suite. According to SWIG's documentation, the failure of some tests should not be considered harmful.

Now, as the root user:

make install &&
install -v -m755 -d /usr/share/doc/swig-3.0.4 &&
cp -v -R Doc/* /usr/share/doc/swig-3.0.4

Command Explanations

--without-<language>: allows disabling the building of tests and examples for <language>, but all the languages capabilities of SWIG are always built. We use it for Clisp, because the SWIG implementation is very incomplete and a lot of tests fail.


Installed Programs: swig and ccache-swig
Installed Library: None
Installed Directories: /usr/share/swig/3.0.4 and /usr/share/doc/swig-3.0.4

Short Descriptions


takes an interface file containing C/C++ declarations and SWIG special instructions, and generates the corresponding wrapper code needed to build extension modules.


is a compiler cache, which speeds up re-compilation of C/C++/SWIG code.

Last updated on 2015-01-19 06:03:51 +0000