Compilation of SPM MEX files¶
What are MEX files?
MEX files are MATLAB functions implemented in C/C++. Contrary to functions implemented in pure MATLAB, they need to be compiled in order for the MATLAB interpreter to be able to call them. Once compiled, they correspond to platform-specific files *.mex*
.
Instructions¶
Pre-compiled MEX files are provided with the SPM distribution so you shouldn’t need to compile the MEX files yourself. We still provide here platform-specific instructions to compile all the MEX files for your machine if the shipped ones were incompatible with your OS version.
Troubleshooting¶
Platform-specific throubleshooting is available with the links above. We list here error messages and solutions that are common across platforms.
bad image handle dimensions
error
The error “bad image handle dimensions
” when trying to display an image is an indication that the MEX files are not compatible with your platform and should be recompiled.
Automatic recompilation on GitHub Actions¶
How is the recompilation triggered?
If new .c
, .cpp
, .h
or .hpp
files or changes of those are pushed to main
, the compile MEX action will automatically run and recompile all MEX files. In can also be triggered manually, which works for a any branch.
The compiled MEX files will be available as zip a file under the compile MEX action by selecting the corresponding run of the action and downloading the spm-mex-all.zip
file. It contains compiled MEX files for Windows, Linux, MacOS (Intel) and MacOS (Apple Silicon).
The suggested steps after changing or adding new c code are:
- Confirm that the automatic tests still succeed
- Download the automatically compiled MEX files
- Manually add the MEX files of the corresponding change to the SPM repository (.mexa64, .mexmaca64, .mexmaci64, .mexw64)
Note: Currently, the action doesn’t compile the external c dependencies. This is because of a problem of compiling the fieldtrip dependency on windows.