R2017a mex gfortran uses obsolete options

8 views (last 30 days)
tmichoel on 17 May 2017
Commented: Robert on 28 Jan 2021
Using R2017a with gfortran/GCC v7.1.0 on OS X 10.11, configuring MEX to use gfortran works out of the box ( this patch is no longer required), but compiling fortran files runs into 2 issues.
  1. If the (default) option "-largeArrayDims" is used, gfortran is called with option "-i8", causing an error "gfortran: error: unrecognized command line option '-i8'; did you mean '-k8'?" It appears that "-i8" is an obsolete option, see here. If the option "-compatibleArrayDims" is used, mex does not use "-i8" and runs without this error.
  2. If the first error is circumvented, mex proceeds to the next step (mex file creation), but aborts with an error "ld: library not found for -lgfortranbegin". Again, use of this option appears to be obsolete, see here.
To work around these issues, it is possible to run mex with "-n" option to obtain the list of command mex would execute, for instance:
mex -n convec.F
Building with 'gfortran'.
/usr/local/Cellar/gcc/7.1.0/bin/gfortran -c -DTARGET_API_VERSION=700 -DUSE_MEX_CMD -I"/Applications/MATLAB_R2017a.app/extern/include" -I"/Applications/MATLAB_R2017a.app/simulink/include" -fexceptions -m64 -fbackslash -i8 -O /Users/tmichoel/tmp/convec.F -o /var/folders/53/l3qnbpyd71n_lpn21j4sdmzrmfcfyn/T/mex_74280327025054_48031/convec.o
/usr/local/Cellar/gcc/7.1.0/bin/gfortran -c -DTARGET_API_VERSION=700 -DUSE_MEX_CMD -I"/Applications/MATLAB_R2017a.app/extern/include" -I"/Applications/MATLAB_R2017a.app/simulink/include" -fexceptions -m64 -fbackslash -i8 -O /Applications/MATLAB_R2017a.app/extern/version/fortran_mexapi_version.F -o /var/folders/53/l3qnbpyd71n_lpn21j4sdmzrmfcfyn/T/mex_74280327025054_48031/fortran_mexapi_version.o
xcrun -sdk macosx10.12 clang -Wl,-twolevel_namespace -undefined error -mmacosx-version-min=10.12 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -bundle -Wl,-exported_symbols_list,"/Applications/MATLAB_R2017a.app/extern/lib/maci64/fexport.map" -O /var/folders/53/l3qnbpyd71n_lpn21j4sdmzrmfcfyn/T/mex_74280327025054_48031/convec.o /var/folders/53/l3qnbpyd71n_lpn21j4sdmzrmfcfyn/T/mex_74280327025054_48031/fortran_mexapi_version.o -L"/Applications/MATLAB_R2017a.app/bin/maci64" -lmx -lmex -lmat -L"/usr/local/Cellar/gcc/7.1.0/lib/gcc/7" -lgfortran -L"/usr/local/Cellar/gcc/7.1.0/lib/gcc/7" -lgfortranbegin -o convec.mexmaci64
rm -f /var/folders/53/l3qnbpyd71n_lpn21j4sdmzrmfcfyn/T/mex_74280327025054_48031/convec.o
rm -f /var/folders/53/l3qnbpyd71n_lpn21j4sdmzrmfcfyn/T/mex_74280327025054_48031/fortran_mexapi_version.o
MEX completed successfully.
and then run each of these commands manually on the command line after removing the "-i8" and "-lgfrortranbegin" options (as well as the "/var/..." directories). This results in a fully functional mex file:
>> x = [3.000 - 1.000i, 4.000 + 2.000i, 7.000 - 3.000i];
>> y = [8.000 - 6.000i, 12.000 + 16.000i, 40.000 - 42.000i];
>> z = convec(x,y)
z =
1.0e+02 *
0.1800 - 0.2600i 0.9600 + 0.2800i 1.3200 - 1.4400i 3.7600 - 0.1200i 1.5400 - 4.1400i
I also tried replacing "-i8" by "-fdefault-integer-8" as suggested in the first link above, but this resulted in a segmentation fault.
Has anyone else encountered these issues, or did I somehow misconfigure mex?

Answers (1)

Sangeetha Jayaprakash
Sangeetha Jayaprakash on 22 May 2017
It looks like you are using GNU Fortran gfortran to compile the fortran MEX file.
I believe that MATLAB R2015a was the last release that supported 'gfortran' on OS X. For MATLAB R2017a, the supported compilers are Intel Parallel Studio XE 2015,2016 and 2017 for Fortran.
The list of supported compilers can be found in this link:

Community Treasure Hunt

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

Start Hunting!