This package provides scripts that attempt to facilitate setting up the MATLAB MEX on macOS or Windows. For Fortran, it will install (automatically) the Fortran compiler from Intel oneAPI, available free of charge. The setup on Linux is trivial and Linuxers should be capable of handling it half asleep.
Whether the method here works or not, it depends on the configuration of your system and your MATLAB. Trying will not hurt. In case it fails, you need to consult a local MATLAB expert or the technical support of MathWorks about "how to set up MEX".
Before starting, clone this repository. Then do the following according to your system (macOS or Windows) and your need (C or Fortran).
-
C
-
Install Xcode with Clang
(After installing Xcode, type in Terminal: xcodebuild -find make xcodebuild -find gcc xcodebuild -find g++ xcodebuild -find clang xcodebuild -find clang++)
-
In MATLAB, change the directory to the folder of the repository, run
try_mex_setup('c')
-
-
Fortran
- Install Xcode with Clang
- In terminal, change the directory to the folder of the repository, run
sudo bash install_oneapi_macos.sh
- In MATLAB, change the directory to the folder of the repository, run
try_mex_setup('fortran')
-
C
- Install Microsoft Visual Studio with the "Desktop development with C++" workload
- In MATLAB, change the directory to the folder of the repository, run
try_mex_setup('c')
-
Fortran
- Install Microsoft Visual Studio with the "Desktop development with C++" workload
- In cmd (not PowerShell), change the directory to the folder of the repository, run
install_oneapi_windows.bat
- In MATLAB, change the directory to the folder of the repository, run
try_mex_setup('fortran')
-
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.
-
Choose the version of Xcode or Microsoft Visual Studio according to that of your MATLAB, following the official documentation of MathWorks. The latest version does not necessarily work.