setup_mex: Set up MEX on Windows and macOS for Fortran and C

版本 1.0 (25.7 KB) 作者: Zaikun Zhang
This package provides scripts that facilitate setting up the MATLAB MEX on Windows and macOS for compiling Fortran and C using Intel oneAPI.
229.0 次下载
更新时间 2023/4/18

setup_mex

license Test MEX View setup_mex on File Exchange

What

This package provides scripts that attempt to facilitate setting up the MATLAB MEX, 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). 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 April 2024, we do not support Fortran setup on macOS with silicon chips, because MathWorks requires the NAG 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, 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. 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".

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, 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')

Windows

  • 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.

      -- If your MATLAB version is R2023b or below, then run

      install_oneapi_windows.bat 2023

      -- If your MATLAB version is R2024a or above, then run

      install_oneapi_windows.bat 
    • In MATLAB, change the directory to the folder of the repository, run

      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. The latest version does not necessarily work.

引用格式

Zaikun Zhang (2024). setup_mex: Set up MEX on Windows and macOS for Fortran and C (https://github.com/equipez/setup_mex/releases/tag/v1.0), GitHub. 检索时间: .

MATLAB 版本兼容性
创建方式 R2023a
与 R2018a 及更高版本兼容
平台兼容性
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0

要查看或报告此来自 GitHub 的附加功能中的问题,请访问其 GitHub 仓库
要查看或报告此来自 GitHub 的附加功能中的问题,请访问其 GitHub 仓库