Skip to content
William S Fulton edited this page Sep 22, 2024 · 23 revisions

Getting Started

This page contains advice on what to install in order to get the SWIG examples up and running quickly. It also contains information for building the SWIG executable and distribution tarball and Windows distribution zip file.

Linux - Ubuntu

Installing applications is very easy on Ubuntu (one of the most popular Linux operating systems) and the following should have you up and running very quickly. The instructions have worked on Hardy Heron, Intrepid Ibex, Lucid Lynx, Maverick Meerkat, Precise Pangolin, Quantal Quetzal, Raring Ringtail, Saucy Salamander, Trusty Tahr, Xenial Xerus, Bionic Beaver, Focal Fossa, Jammy Jellyfish, Noble Numbat and are also likely to be suitable for Debian. Run the following to get the essential tools to build the SWIG executable from the distribution tarball, eg swig-4.0.0.tar.gz:

sudo apt-get install build-essential libpcre2-dev libpcre3-dev

Note that libpcre2-dev is needed for swig-4.1.0 and later and libpcre3-dev is for prior versions.

If you want to build the SWIG executable from Git (ie you are not using the distribution tarball) run the following in addition to the above:

sudo apt-get install autoconf automake libtool bison git

Add some additional dependencies for the test-suite:

sudo apt-get install libboost-dev

Run the following which installs the languages that have supported status:

#Note: Perl is installed by default
sudo apt install golang-go # For Go language (Ubuntu 12.04 - Precise Pangolin or later)
sudo apt install guile-2.2-dev (Ubuntu 18.04 - Bionic Beaver or later)
sudo apt install nodejs node-gyp # Javascript Node (Ubuntu 14.04 - Trusty Tahr or later)
sudo apt install libwebkit2gtk-4.1-dev # Javascript JSC (Ubuntu 24.04 - Noble Nombat or later)
sudo apt install lua5.3 liblua5.3-dev
sudo apt install mono-devel # C#
sudo apt install octave-dev # (Ubuntu 22.04 - Jammy Jellyfish or later)
sudo apt install default-jdk-headless # Java
sudo apt install php-cli php-dev
sudo apt install python-dev # Python 2 (no longer available from Ubuntu 22.04 - Jammy Jellyfish)
sudo apt install python3-dev # Python 3 
sudo apt install r-base # R language
sudo apt install ruby ruby-dev
sudo apt install scilab libxml2-dev # For Scilab (Ubuntu 12.04 - Precise Pangolin or later)
sudo apt install tcl-dev

One line installs for all of the above...

For Ubuntu Noble Numbat, use:

sudo apt install build-essential libpcre2-dev libpcre3-dev autoconf automake libtool bison git libboost-dev golang-go guile-2.2-dev nodejs node-gyp libwebkit2gtk-4.1-dev lua5.3 liblua5.3-dev mono-devel octave-dev default-jdk-headless php-cli php-dev python3-dev r-base ruby ruby-dev tcl-dev scilab libxml2-dev

For Ubuntu Jammy Jellyfish, use:

sudo apt install build-essential libpcre2-dev libpcre3-dev autoconf automake libtool bison git libboost-dev golang-go guile-2.2-dev nodejs node-gyp libwebkit2gtk-4.0-dev lua5.3 liblua5.3-dev mono-devel octave liboctave-dev default-jdk-headless php-cli php-dev python3-dev r-base ruby ruby-dev tcl-dev scilab libxml2-dev

For Ubuntu Focal Fossa, use:

sudo apt install build-essential libpcre2-dev libpcre3-dev autoconf automake libtool bison git libboost-dev golang-go guile-2.2-dev nodejs node-gyp libwebkit2gtk-4.0-dev lua5.3 liblua5.3-dev mono-devel octave liboctave-dev default-jdk-headless php-cli php-dev python-dev python3-dev r-base ruby ruby-dev tcl-dev scilab libxml2-dev

For Ubuntu Bionic Beaver, use:

sudo apt install build-essential libpcre3-dev autoconf automake libtool bison git libboost-dev golang-go guile-2.2-dev            lua5.3 liblua5.3-dev mono-devel octave liboctave-dev default-jdk-headless php-cli php-dev python-dev python3-dev r-base ruby ruby-dev tcl-dev scilab libxml2-dev

For Ubuntu Xenial Xerus, use:

sudo apt install build-essential libpcre2-dev libpcre3-dev autoconf automake libtool bison git libboost-dev golang-go guile-2.0-dev nodejs npm lua5.3 liblua5.3-dev mono-devel octave liboctave-dev openjdk-9-jdk-headless php-cli php-dev python-dev python3-dev r-base ruby ruby-dev tcl-dev scilab libxml2-dev

For Ubuntu Trusty Tahr, use:

sudo apt-get install build-essential libpcre2-dev libpcre3-dev autoconf automake libtool bison git libboost-dev python-dev ruby ruby-dev tcl-dev mono-devel lua5.2 liblua5.2-dev octave liboctave-dev php5-cli php5-dev openjdk-7-jdk guile-2.0-dev 

For Ubuntu Raring Ringtail and Saucy Salamander, use:

sudo apt-get install build-essential libpcre2-dev libpcre3-dev autoconf automake libtool bison git libboost-dev python-dev ruby ruby-dev tcl-dev mono-devel lua5.1 liblua5.1-0-dev octave liboctave-dev php5-cli php5-dev openjdk-7-jdk guile-2.0-dev

For older versions of Ubuntu:

sudo apt-get install build-essential libpcre2-dev libpcre3-dev autoconf automake libtool bison subversion libboost-dev python-dev ruby ruby1.8-dev tcl8.4-dev mono-devel lua5.1 liblua5.1-0-dev octave2.9 octave2.9-headers php5-cli php5-dev openjdk-6-jdk

Bison may need to be built from source for swig-4.2 and later if using an old version of Ubuntu. bison-3.5 or later is required in turn is needed as the distro supplied versions of bison for Ubuntu 18.04 - Bionic Beaver and earlier have versions which are too old. The commands below build and install bison-3.5.1 from the Ubuntu Focal 20.04 source package repo: https://packages.ubuntu.com/source/focal/bison and worked on Ubuntu Bionic 18.04. Versions of bison even newer than bison-3.5 require autotool upgrades, which is even more challenging.

sudo apt-get -y remove bison # remove old version if present
sudo apt-get -y install dpkg-dev help2man
wget http://archive.ubuntu.com/ubuntu/pool/main/b/bison/bison_3.5.1 dfsg-1.dsc http://archive.ubuntu.com/ubuntu/pool/main/b/bison/bison_3.5.1 dfsg.orig.tar.xz http://archive.ubuntu.com/ubuntu/pool/main/b/bison/bison_3.5.1 dfsg-1.debian.tar.xz
dpkg-source -x bison_3.5.1 dfsg-1.dsc
cd bison-3.5.1 dfsg/
dpkg-buildpackage -rfakeroot -b -d --no-sign
sudo dpkg -i ../bison_3.5.1 dfsg-1_amd64.deb

The following installs a few other useful packages and languages that have experimental status:

sudo apt install python3-pip && sudo pip3 install pycodestyle # For python style checking (Ubuntu 18.04 - Bionic Beaver and later)
sudo apt install racket # Mzscheme/Racket # (Ubuntu 10.10 - Maverick Meerkat or later)
sudo apt install ocaml camlp4
sudo apt install ldc # For D language (Ubuntu 10.10 - Maverick Meerkat or later)

Older versions:

sudo apt-get install lua5.1 liblua5.1-0-dev (Ubuntu 13.04 - Raring Ringtail and earlier)
sudo apt-get install mzscheme drscheme # Mzscheme (Ubuntu 10.04 - Lucid Lynx and earlier)
sudo apt-get install guile-1.8-dev # (Ubuntu 14.04 - Trusty Tahr and earlier)
sudo apt-get install libwebkitgtk-dev # Javascript JSC (Ubuntu 14.04 - Trusty Tahr or later)
sudo apt-get install libwebkit2gtk-4.0-dev # Javascript JSC (Ubuntu 22.04 - Jammy Jellyfish or earlier)
sudo apt-get install libv8-dev # Javascript v8 (Ubuntu 14.04 - Trusty Tahr to Ubuntu 18.04 - Bionic Beaver). Superceded by libnode-dev.
sudo apt-get install octave2.9 octave2.9-headers # (Ubuntu 11.04 - Natty Narwhal and earlier)
sudo apt-get install octave3.2 octave3.2-headers # (Ubuntu 12.04 - Precise Pangolin and earlier)
sudo apt-get install octave liboctave-dev # (Ubuntu 22.04 - Jammy Jellyfish and earlier)
sudo apt-get install php5-cli php5-dev (Ubuntu 14.04 - Trusty Tahr and earlier)
sudo apt-get install ruby1.8 ruby1.8-dev (Ubuntu 12.04 - Precise Pangolin and earlier)
sudo apt-get install tcl8.4-dev # (Ubuntu 12.04 - Precise Pangolin and earlier)

To build from the latest cutting edge version using Git, take a look at http://www.swig.org/svn.html, but simply all that is needed is:

git clone https://github.com/swig/swig.git
cd swig
./autogen.sh && ./configure && make

To build from an official release tarball, for example for swig-4.0.0.tar.gz (note that you do not need to run autogen.sh when using an unmodified tarball):

tar -zxf swig-4.0.0.tar.gz
cd swig-4.0.0
./configure && make

To run the entire test-suite (takes a long time):

make -k check-test-suite

To run the test-suite just for language xxx, replace xxx with one of csharp, java, perl5, python, ruby, tcl etc:

make check-xxx-test-suite

Further details on how to run the test-suite and write test cases: http://www.swig.org/Doc4.2/Extending.html#Extending_test_suite

To run an example, cd into the directory, then run 'make check', for example:

cd Examples/csharp/class && make check
cd Examples/d/class && make check
cd Examples/java/class && make check
cd Examples/perl5/class && make check
cd Examples/python/class && make check
cd Examples/ruby/class && make check
cd Examples/tcl/class && make check
cd Examples/octave/class && make check

Some other useful bits to install if you are developing SWIG...

sudo apt-get install vim-gtk3 # Vim editor
sudo apt-get install emacs # Emacs editor
sudo apt-get install r-base-html r-doc-pdf r-doc-html # For the R language
sudo apt-get install valgrind # Fantastic error checking tool
sudo apt-get install meld # Visual diff and merge tool

Building a full release

The full distribution can be built quite easily. This includes building the Windows version on Linux. First install the following

sudo apt-get install htmldoc mingw-w64 wine wput tidy yodl

For the official pdf documentation generation wkhtmltopdf patched with qt is required as per instructions in Doc/Manual/Makefile.

Creating the release tarball is done by the Tools/mkdist.py script. Pass the --help option to get a full list of options available, but normally one would just run the following where <version> should be replaced by the version number, eg 3.0.2:

cd Tools
./mkdist.py <version>

Building the Windows binary and the Windows zip file requires the release tarball created above. The script used is Tools/mkwindows.sh and is used as follows:

cd Tools
./mkwindows.sh <version>

Use the --help option to get a full list of options such as building a 32-bit Windows binary instead of the default 64-bit binary (from swig-4.3.0 and later). For 32-bit wine support, you may also need to install and configure 32-bit wine (not covered here).

Linux - SUSE

The Ubuntu guide above can be used except the packages to be installed are different. For openSUSE 13.1, the required packages can be installed as follows:

sudo zypper install gcc-c   make pcre-devel pcre2-devel autoconf automake libtool bison subversion git-core boost-devel
sudo zypper install go guile-devel java-devel lua-devel octave-devel mono-core php5-devel python-devel ruby-devel tcl-devel

Note that pcre2-devel is needed for swig-4.1.0 and later and pcre-devel is for prior versions.

Apple OSX

The following works on OSX Mountain Lion. If you don't have Xcode or the Xcode command line tools installed, download and install the "Command Line Tools (OS X Mountain Lion) for Xcode" from http://developer.apple.com/downloads. This will install the required C and C compilers for building SWIG.

The remaining dependencies rely on using brew - http://brew.sh. If you don't have brew installed, run the ruby script to install brew as described at http://brew.sh and follow the instructions.

The prerequisites for building SWIG and running tests can be installed by running:

brew install git automake pcre pcre2 boost

Note that pcre2 is needed for swig-4.1.0 and later and pcre is for prior versions.

The dependencies for using Php, Python, Ruby or Tcl as your target language will already be installed. However, if you want wrappers for Lua and Guile run:

brew install lua guile

If you don't have java installed and you want Java as your target language, type out 'java -version' in a command prompt and you will be prompted to install the Java runtime.

SWIG can now be built and used. Follow the instructions at http://www.swig.org/svn.html for downloading and building a development version of SWIG from github. The examples and test-suite can be run as described above for Linux - Ubuntu.

Windows

Please see the instructions at http://www.swig.org/Doc4.2/Windows.html. Also see Building a full release above for the mkwindows.sh script that is used to build the official Windows release.

Clone this wiki locally