Can I configure a mex compiler on toolbox installation?

I have set of XML mexopts files and helper files that enable the use of the MinGW and Cygwin Fortran compilers on Windows on pre-R2024a releases. I'd like to package these in a toolbox like the compiler support package from Mathworks: https://www.mathworks.com/matlabcentral/fileexchange/52848-matlab-support-for-mingw-w64-c-c-fortran-compiler
On a fresh install of Matlab (i.e. mex not previously set up), installing that toolbox sets up the MinGW compilers. I don't see a mechanism in the toolbox packaging tool to do this, though, and the only other answers I could find on this question suggest either having a check run the first time the user executes a toolbox function or having the user run a setup function.
Is there a way to do this automatically for user-created toolboxes?

3 Comments

I've never used it so not sure if it would make it possible, but @Image Analyst posted a link to a packaging tool that has much more flexibility than the supplied tool. <Gammadyne Centurion Setup>. You might explore its possibilities or maybe @Image Analyst himself will see this and have ideas.
It would indeed be a most welcome addition to the Fortran mex world -- I gather you must have figured out how to link with the MS/Intel libraries distributed with the earlier releases. I looked at this several years ago and was never able to resolve the difference in naming conventions used by MinGW vis a vis MS and at that time at least, there was no way to cause the symbol names to have a matching decoration style. If you figured out something I didn't or MinGW changed since, that's wonderful news, indeed.
Now if only Mathworks would at least get to F95 interfaces and support, what more F2008+
F2018 (adopted Nov, 2018) is fully implemented by all major compilers.
F2023 (Nov 2023) is the current and is being implemented but probably another year or so before full compliance.
With the adoption of C interoperability in F2003 (now over 20(!!!) years ago) there's no longer an excuse to hamstring the full API mex functions.
After looking at a few different options, I've decided there will just have to be some user involvement in the setup process.
Yes, you can get the symbol names to match, but you can't do it with compiler options alone. I actually had this working in 2019, but it was specific to my company's internal dev environment, so I've had to spend some time updating it not to assume that environment. I'm in the process of adding support for Mac, too, which comes with its own set of quirks (e.g. mex on Mac adds -i8 to FFLAGS automatically and invisibly, it's not anywhere in the config, so you have to use a variable with some name other than FFLAGS to avoid an invalid option error when using gcc). I'm working on getting all the necessary approvals to publish the toolbox publicly and will hopefully have some version of it up soon.
Fully agreed the Fortran mex interfaces need to be brought up to date. Also, having gotten this working, and knowing what it takes to support gcc, I'm baffled at MathWorks' insistence that there are technical limitations preventing gfortran from working on releases prior to R2024a.
"... I'm baffled at MathWorks' insistence that there are technical limitations preventing gfortran from working on releases prior to R2024a."
Agreed. Since gfortran is simply a frontend translator and not a full Fortran compiler, it's always been just an excuse. I wish they would just tell you the libraries and link and let one forego all the mex stuff they've hidden. Be much more simple.
It seems strange to me given the ubiquitous nature of the MS/Intel compilers that gcc doesn't have a more generic set of ptragmas to handle such-- you would have thought somebody would have found the need and added it ere now.
I last did any serious Fortran mex with CVF/DVF in support of a real time fossil power plant thermal performance code moved from VAX/VMS to OS/2 to WinNT ages ago. It's still running nearly 30 years after at the power plants; the major utility that sponsored the conversion warehoused a stash of office 386's and if one dies, they go get another. <vbg>

Sign in to comment.

Answers (0)

Categories

Products

Release

R2024b

Tags

Asked:

on 6 Feb 2026

Commented:

dpb
on 25 Feb 2026

Community Treasure Hunt

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

Start Hunting!