https://github.com/equipez/setup_mex
This package provides scripts that attempt to facilitate setting up the MATLAB MEX.
https://github.com/equipez/setup_mex
c compilers fortran ifort intel macos matlab matlab-mex mex mex-files mex-functions mex-gateway mex-interface numerical-computation oneapi scientific-computing windows
Last synced: 19 days ago
JSON representation
This package provides scripts that attempt to facilitate setting up the MATLAB MEX.
- Host: GitHub
- URL: https://github.com/equipez/setup_mex
- Owner: equipez
- License: lgpl-3.0
- Created: 2023-01-09T06:06:24.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-09-03T16:17:50.000Z (5 months ago)
- Last Synced: 2025-09-03T17:40:37.491Z (5 months ago)
- Topics: c, compilers, fortran, ifort, intel, macos, matlab, matlab-mex, mex, mex-files, mex-functions, mex-gateway, mex-interface, numerical-computation, oneapi, scientific-computing, windows
- Language: MATLAB
- Homepage:
- Size: 217 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# `setup_mex`
[](https://github.com/equipez/setup_mex/blob/main/LICENCE.txt)
[](https://github.com/equipez/setup_mex/actions/workflows/setup_mex.yml)
[](https://www.mathworks.com/matlabcentral/fileexchange/127968-setup_mex)
## What
This package provides scripts that attempt to facilitate setting up the
[MATLAB MEX](https://www.mathworks.com/help/matlab/ref/mex.html), focusing on macOS and Windows.
Note that MATLAB requires you to install a [supported (C or Fortran) compiler along with Xcode (on macOS with Intel chips)
or Microsoft Visual Studio (on Windows)](https://www.mathworks.com/support/requirements/previous-releases.html).
This package is **not** a hacking tool to circumvent these requirements,
but a tool to help MATLAB recognize your compiler after these requirements are satisfied.
As of 2025, we do not support Fortran setup on macOS with silicon chips, because MathWorks requires the [NAG Fortran compiler](https://nag.com/fortran-compiler/) for such a setup, which is not available for free.
For Fortran, this package provides scripts (`install_oneapi_macos.sh` for macOS with Intel chips and `install_oneapi_windows.bat` for Windows) to help
you install the Fortran compiler from
[Intel oneAPI](https://www.intel.com/content/www/us/en/developer/tools/oneapi/overview.html),
available free of charge. This is the compiler officially supported by MATLAB.
This package has been successfully tested on all recent releases of MATLAB under recent versions of Windows and macOS via
[GitHub Actions](https://github.com/equipez/setup_mex/actions/workflows/setup_mex.yml).
Nevertheless, I will not be surprised if it does not work on your machine. **In that case,
you need to consult a local MATLAB expert or the technical support
of MathWorks about ["how to set up MEX"](https://www.mathworks.com/help/matlab/ref/mex.html)**.
## How
Before starting, clone this repository. Then do the following according to your system (macOS or Windows) and your need (C or Fortran).
### macOS with Intel chips
- C
- Install Xcode with Clang
- In MATLAB, change the directory to the folder of the repository, and run
```matlab
try_mex_setup('c')
```
- Fortran
- Install Xcode with Clang
- In [terminal](https://support.apple.com/en-hk/guide/terminal/apd5265185d-f365-44cb-8b09-71a064a42125/mac), change the directory to the folder of the repository, and run
```bash
sudo bash install_oneapi_macos.sh
```
- In MATLAB, change the directory to the folder of the repository, and run
```matlab
try_mex_setup('fortran')
```
### Windows
- C
- Install Microsoft Visual Studio with the "Desktop development with C++" workload
- In MATLAB, change the directory to the folder of the repository, and run
```matlab
try_mex_setup('c')
```
- Fortran
- Install Microsoft Visual Studio with the "Desktop development with C++" workload
- In [**cmd**](https://en.wikipedia.org/wiki/Cmd.exe) (not [PowerShell](https://en.wikipedia.org/wiki/PowerShell)), change the directory to the folder of the repository, and run
```bash
install_oneapi_windows.bat YEAR_OF_MATLAB_VERSION
```
where **`YEAR_OF_MATLAB_VERSION` is the year of your MATLAB version**, e.g., `2024` for MATLAB R2024a.
- In MATLAB, change the directory to the folder of the repository, and run
```matlab
try_mex_setup('fortran')
```
## Remarks
1. Always adopt the **default options** (e.g., installation directory) when installing Xcode (on macOS) or
Microsoft Visual Studio (on Windows). Otherwise, MATLAB may not be able to locate them.
2. Choose the version of Xcode or Microsoft Visual Studio according to that of your
MATLAB, following [the official documentation of MathWorks](https://www.mathworks.com/support/requirements/supported-compilers.html).
The latest version does not necessarily work.