Skip to content

Compilation of SPM on Windows

This page describes the compilation of SPM MEX files on Windows 10 with MATLAB R2018b (9.5) and MSYS2 MinGW-w64 GCC; identical or very similar instructions should work with newer versions of Windows, MATLAB and MSYS2 MinGW. It also provides instructions to compile SPM for the Octave package of MSYS2.

Tip

If you use other versions of MATLAB and/or compiler, make sure that they are compatible by checking the list of supported compilers and adjust the MATLAB path accordingly in the commands below.

Installation of MSYS2/MinGW-w64

Download and install MSYS2 from https://www.msys2.org/ in directory C:\msys64.

Then, from MSYS2, type:

pacman -Syu
pacman -Su  
pacman -S --needed base-devel mingw-w64-x86_64-toolchain

Configuration of MATLAB compilation environment

Start MATLAB and type:

setenv('MW_MINGW64_LOC', 'C:\msys64\mingw64')
mex -setup
% MEX configured to use 'MinGW64 Compiler (C)' for C language compilation.

Do not worry if this warning is displayed:

Warning: The MATLAB C and Fortran API has changed to support MATLAB
     variables with more than 2^32-1 elements. You will be required
     to update your code to utilize the new API.

Compilation

In MSYS2, move to the SPM source directory (./src/) with

cd  /c/Documents and Settings/<login>/Documents/MATLAB/spm/src

then set the PATH appropriately

PATH=/c/ProgramFiles/MATLAB/R2018b/bin/win64:${PATH} 
export MW_MINGW64_LOC=/c/msys64/mingw64/
PATH=/c/msys64/mingw64/bin/:${PATH}

and finally type the following to start the compilation process

make distclean
make && make install
make external-distclean
make external && make external-install

This will generate *.mexw64 MEX files.

Notes for compilation with MSYS2 for Octave

Install mingw-w64-octave

pacman -S mingw64/mingw-w64-x86_64-octave

then start Octave with:

/mingw64/bin/octave --gui

and compile with:

cd('/c/Documents and Settings/<login>/Documents/MATLAB/spm/src');
system('make distclean PLATFORM=octave');
system('make PLATFORM=octave && make install PLATFORM=octave');
system('make external-distclean PLATFORM=octave');
system('make external PLATFORM=octave && make external-install PLATFORM=octave');

This will generate *.mex MEX files.