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.
Are Fortran mex files restricted to fixed format?
1 view (last 30 days)
Show older comments
Commented: Josh G. on 8 Apr 2019
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
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?
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!