mesonbuild/meson

Feature Request: Support for a MATLAB module

Open

#15668 opened on Apr 1, 2026

View on GitHub
 (2 comments) (0 reactions) (0 assignees)Python (4,978 stars) (1,465 forks)batch import
enhancementhelp wanted

Description

MATLAB has two complementary features for interacting with C++ code

  1. Calling MATLAB functions with C++, known as the "MATLAB Engine API for C++"
  2. Calling C++ (or C, or Fortran) from MATLAB, known as "Mex functions"

(There is a 3rd thing called clibgen but I am explicitly not talking about that in this feature request)

According to MATLAB's documentation, the "official" way to create any of the above is through the matlab editor using the mex command with a "supported compiler". There is, however, an unofficial way of using mex, as described here:

The mex command is the only supported way to compile MEX files. As an exception, you may compile MEX files without the mex command. For instance, if you use a compiler that is "unknown" to the mex command or you use an IDE that cannot be integrated with the mex command.

Reference for the above (as well as an example makefile for compiling mex on Linux)

This feature request is for a module that can help detect MATLAB and set up the required flags and options to compile a mex function. I believe this is in scope for meson given the developer's opinions that meson should provide a rich set of tools, and solve a problem once, for everyone. This is one such case where meson could more easily solve this problem internally instead of relying on meson as a language or shelling out to robustly add this functionality. There are various intricacies of mex that require platform and version specific flags/options to compile correctly.

Futhermore, CMake has a very similar feature: FindMatlab Module.

Contributor guide