Are Fortran mex files restricted to fixed format?

4 views (last 30 days)
I'm learning to mex Fortran files and am having trouble with the timestwo.F tutorial. I'm able to compile and run the built-in, fixed format example file without a problem. However, when I tried to compile my own free format file named timestwo.f90, I got a bunch of errors about invalid preprocessor directives.
From a MATLAB Answers question, I found that I needed to capitalize the f in the file extension. mex timestwo.F90 completes successfully. When I try to use the function, though, I get an error:
Invalid MEX-file '/home/user/Documents/MATLAB/mex/timestwo.mexa64': /home/user/Documents/MATLAB/mex/timestwo.mexa64: undefined
symbol: mxgetdoubles_
The only difference between my file and the example file is that mine is free format and doesn't include the #if MX_HAS_INTERLEAVED_COMPLEX check found in the example file. Is this an issue with support for free format source?

Answers (1)

Josh G.
Josh G. on 28 Mar 2019
I figured this out a few minutes after posting my question by trying something I thought I had already tried: adding the -R2018a option. My guess is I had to both add -R2018a to the mex options and change the file extension to .F90, which I had probably tried individually but not simultaneously. I'll leave the question up in case someone has this same problem in the future when getting into using Fortran mex files.
Josh G.
Josh G. on 8 Apr 2019
Using the -R2018a option was why my code started working, but you're right that it has nothing to do with formatting.
It turns out mxGetDoubles was introduced in R2018b; you have to use mxGetPr for pre-R2018b compatibility.
I'm on Linux, so fortunately I don't have a fixed format flag built into the gfortran mexopts file, but over the past week I've had to work on a Windows system a good bit and have had to deal with repeatedly removing the /fixed flag while resetting the compiler configuration. It's beyond me why they would include that when it doesn't cause any problems to remove it.

Sign in to comment.


Find more on Fortran with MATLAB in Help Center and File Exchange





Community Treasure Hunt

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

Start Hunting!

Translated by