Skip to content

cross compiling SWIG for Windows on macOS

Robin Verschueren edited this page Jun 20, 2018 · 1 revision

SWIG doesn't come with CMake, so unfortunately we must cross-compile it for Windows. Note that if you also want to build Casadi from sources with SWIG, you need PCRE support. Here is how to build first PCRE and then SWIG, creating a swig.exe executable that runs on Windows.

  1. Make sure you have mingw-w64 installed, e.g. via Homebrew
  2. Download/clone SWIG from https://github.com/jaeandersson/swig ; make sure you are on the 'matlab' branch
  3. Download PCRE from this link
  4. Don't unpack it, put it in the SWIG_ROOT folder
  5. Cross-compile PCRE, by running from SWIG_ROOT (unfortunately, the configure script does not figure out the paths to the cross-compiling toolchain on its own):

AR=x86_64-w64-mingw32-ar STRIP=x86_64-w64-mingw32-strip RANLIB=x86_64-w64-mingw32-ranlib Tools/pcre-build.sh --host=x86_64 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++

  1. Configure SWIG, by running from SWIG_ROOT:

./configure --prefix=$(pwd)/swig_install --host=x86_64 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++

  1. make install

If everything goes well, you should have a swig.exe in your SWIG_ROOT/swig_install folder.