Bug in MATLAB R2022a: MEX does not support gfortran 8.x as specified in the official documentation
Show older comments
Update (20220406): The MathWorks MEX team has confirmed this problem as a bug of MATLAB R2022a. A workaround is provided by the MEX team, as detailed in the accepted answer.
------------------------
Is there any staff of MathWorks watching this forum? Thank you for having a look at this bug. I submitted a bug report, but no real response is received. No technical support is needed, but it would be great if MathWorks can fix this bug in the product --- or maybe correct the documentation mistake. Thank you very much.
------------------------
According to the official documentation, MATLAB R2022a supports gfortan8.x as the Fortran compiler for MEX on Linux. However, MATLAB R2022a with gfortran 8.3.0 on Ubuntu 20.04 fails to run the following code.
mex('-setup', '-v', 'FORTRAN');
mex('-v', fullfile(matlabroot, 'extern', 'examples', 'refbook', 'timestwo.F'));
The error message is
Error using mex
gfortran: error: unrecognized command line option ‘-fallow-argument-mismatch’; did you mean
‘-Wno-argument-mismatch’?
The problem is reproduced on GitHub Actions. Nevertheless, gfortran 10 and 11 succeed, even though they are not supported officially.
Those who have MATLAB R2022a installed on Ubuntu may have a try on your side. Thank you very much!
------------------------
Update: Why does the error occur?
According to the documentations of gfortran 10.1.0 and gfortran 9.4.0, the -fallow-argument-mismatch flag was first introduced to gfortran in 10.1.0. Therefore, there is no hope that gfortran 8.x could recognize it.
Below are the MEX configuration files of MATLAB Version 9.12.0.1896817 (R2022a, Operating System: Linux 4.14.215-0414215-generic). As we can see, gfortran6.xml specifies -fallow-argument-mismatch as a compilation option. That is why gfortran 8.x cannot work with it.
BTW, another question: What is the relation and difference between gfortran6.xml and gfortran.xml? Which one defines the compilation options when MEX is invoked? In my investigation, it seems that gfortran6.xml is playing the role, although the name of this file is a bit confusing --- I thought it was the configration for gfortran 6 or below.
1. gfortran6.xml located at fullfile(matlabroot,'bin', 'glnxa64', 'mexopts', 'gfortran6.xml'):
<?xml version="1.0" encoding="UTF-8" ?>
<config
Name="gfortran"
ShortName="gfortran"
Manufacturer="GNU"
Version="$GFORTRAN_VERSION"
Language="FORTRAN"
Priority="A"
Location="$GFORTRAN_INSTALLDIR" >
<Details
CompilerExecutable="$FC"
CompilerDefines="$DEFINES"
CompilerFlags="$FFLAGS"
OptimizationFlags="$FOPTIMFLAGS"
DebugFlags="$FDEBUGFLAGS"
IncludeFlags="$INCLUDE"
LinkerLibraries="$LINKLIBS"
LinkerOptimizationFlags="$LDOPTIMFLAGS"
LinkerDebugFlags="$LDDEBUGFLAGS"
CompilerDefineFormatter="-D%s"
LinkerLibrarySwitchFormatter="-l%s"
LinkerPathFormatter="-L%s"
/>
<vars
CMDLINE1="$FC -c $DEFINES $INCLUDE $FFLAGS $OPTIM $SRC -o $OBJ"
CMDLINE2="$LDF $LDFLAGS $LDTYPE $LINKOPTIM $LINKEXPORTVER $OBJS $FLIBS $LINKLIBS -o $EXE"
FC="$GFORTRAN_INSTALLDIR/gfortran"
DEFINES=""
FFLAGS="-fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -fallow-argument-mismatch"
INCLUDE="-I"$MATLABROOT/extern/include" -I"$MATLABROOT/simulink/include""
FOPTIMFLAGS="-O2"
FDEBUGFLAGS="-g"
LDF="$FC"
LDFLAGS="-pthread"
LDTYPE="-shared"
LINKEXPORT="-Wl,--version-script,$MATLABROOT/extern/lib/$ARCH/fexport.map"
LINKEXPORTVER="-Wl,--version-script,$MATLABROOT/extern/lib/$ARCH/fortran_exportsmexfileversion.map"
MWCPPLIB=""$MATLABROOT/sys/os/$ARCH/orig/libstdc++.so.6""
LINKLIBS="-Wl,-rpath-link,$MATLABROOT/bin/$ARCH -L"$MATLABROOT/sys/os/$ARCH/orig" -L"$MATLABROOT/bin/$ARCH" $MWCPPLIB -lmx -lmex -lmat -lm -L"$GFORTRAN_LIBDIR" -lgfortran"
LDOPTIMFLAGS="-O"
LDDEBUGFLAGS="-g"
MW_GLIBC_SHIM="$MW_GLIBC_SHIM"
OBJEXT=".o"
LDEXT=".mexa64"
SETENV="FC="$FC"
FFLAGS="$FFLAGS $DEFINES"
FOPTIMFLAGS="$FOPTIMFLAGS"
FDEBUGFLAGS="$FDEBUGFLAGS"
LD="$FC"
LDFLAGS="$LDFLAGS $LDTYPE $LINKLIBS $LINKEXPORT"
LDDEBUGFLAGS="$LDDEBUGFLAGS"">
</vars>
<!---Wl,-twolevel_namespace -undefined error $LDFEXPORT-->
<client>
<engine
LINKLIBS="$LINKLIBS $MW_GLIBC_SHIM -leng"
LINKEXPORT=""
LINKEXPORTVER=""
LDEXT=""
LDTYPE=""
/>
</client>
<locationFinder>
<GFORTRAN_INSTALLDIR>
<and>
<or>
<cmdReturns name="which gfortran" />
<fileExists name="/usr/local/bin/gfortran" />
</or>
<dirExists name="$$"/>
</and>
</GFORTRAN_INSTALLDIR>
<GFORTRAN_LIBDIR>
<and>
<or>
<cmdReturns name="which gfortran" />
<fileExists name="/usr/local/bin/gfortran" />
</or>
<cmdReturns name="gfortran -print-file-name=libgfortran.so" />
<dirExists name="$$" />
</and>
</GFORTRAN_LIBDIR>
<GFORTRAN_VERSION>
<and>
<or>
<cmdReturns name="which gfortran" />
<fileExists name="/usr/local/bin/gfortran" />
</or>
<cmdReturns name="gfortran -dumpversion | awk -F '.' '$1>=6' " />
</and>
</GFORTRAN_VERSION>
</locationFinder>
</config>
2. gfortran.xml located at fullfile(matlabroot,'bin', 'glnxa64', 'mexopts', 'gfortran.xml'):
<?xml version="1.0" encoding="UTF-8" ?>
<config
Name="gfortran6-"
ShortName="gfortran6-"
Manufacturer="GNU"
Version="$GFORTRAN_VERSION"
Language="FORTRAN"
Priority="B"
Location="$GFORTRAN_INSTALLDIR" >
<Details
CompilerExecutable="$FC"
CompilerDefines="$DEFINES"
CompilerFlags="$FFLAGS"
OptimizationFlags="$FOPTIMFLAGS"
DebugFlags="$FDEBUGFLAGS"
IncludeFlags="$INCLUDE"
LinkerLibraries="$LINKLIBS"
LinkerOptimizationFlags="$LDOPTIMFLAGS"
LinkerDebugFlags="$LDDEBUGFLAGS"
CompilerDefineFormatter="-D%s"
LinkerLibrarySwitchFormatter="-l%s"
LinkerPathFormatter="-L%s"
/>
<vars
CMDLINE1="$FC -c $DEFINES $INCLUDE $FFLAGS $OPTIM $SRC -o $OBJ"
CMDLINE2="$LDF $LDFLAGS $LDTYPE $LINKOPTIM $LINKEXPORTVER $OBJS $FLIBS $LINKLIBS -o $EXE"
FC="$GFORTRAN_INSTALLDIR/gfortran"
DEFINES=""
FFLAGS="-fexceptions -fbackslash -fPIC -fno-omit-frame-pointer"
INCLUDE="-I"$MATLABROOT/extern/include" -I"$MATLABROOT/simulink/include""
FOPTIMFLAGS="-O2"
FDEBUGFLAGS="-g"
LDF="$FC"
LDFLAGS="-pthread"
LDTYPE="-shared"
LINKEXPORT="-Wl,--version-script,$MATLABROOT/extern/lib/$ARCH/fexport.map"
LINKEXPORTVER="-Wl,--version-script,$MATLABROOT/extern/lib/$ARCH/fortran_exportsmexfileversion.map"
MWCPPLIB=""$MATLABROOT/sys/os/$ARCH/orig/libstdc++.so.6""
LINKLIBS="-Wl,-rpath-link,$MATLABROOT/bin/$ARCH -L"$MATLABROOT/sys/os/$ARCH/orig" -L"$MATLABROOT/bin/$ARCH" $MWCPPLIB -lmx -lmex -lmat -lm -L"$GFORTRAN_LIBDIR" -lgfortran -L"$GFORTRANBEGIN_LIBDIR" -lgfortranbegin"
LDOPTIMFLAGS="-O"
LDDEBUGFLAGS="-g"
MW_GLIBC_SHIM="$MW_GLIBC_SHIM"
OBJEXT=".o"
LDEXT=".mexa64"
SETENV="FC="$FC"
FFLAGS="$FFLAGS $DEFINES"
FOPTIMFLAGS="$FOPTIMFLAGS"
FDEBUGFLAGS="$FDEBUGFLAGS"
LD="$FC"
LDFLAGS="$LDFLAGS $LDTYPE $LINKLIBS $LINKEXPORT"
LDDEBUGFLAGS="$LDDEBUGFLAGS"">
</vars>
<!---Wl,-twolevel_namespace -undefined error $LDFEXPORT-->
<client>
<engine
LINKLIBS="$LINKLIBS $MW_GLIBC_SHIM -leng"
LINKEXPORT=""
LINKEXPORTVER=""
LDEXT=""
LDTYPE=""
/>
</client>
<locationFinder>
<GFORTRAN_INSTALLDIR>
<and>
<or>
<cmdReturns name="which gfortran" />
<fileExists name="/usr/local/bin/gfortran" />
</or>
<dirExists name="$$"/>
</and>
</GFORTRAN_INSTALLDIR>
<GFORTRAN_LIBDIR>
<and>
<or>
<cmdReturns name="which gfortran" />
<fileExists name="/usr/local/bin/gfortran" />
</or>
<cmdReturns name="gfortran -print-file-name=libgfortran.so" />
<dirExists name="$$" />
</and>
</GFORTRAN_LIBDIR>
<GFORTRANBEGIN_LIBDIR>
<and>
<or>
<cmdReturns name="which gfortran" />
<fileExists name="/usr/local/bin/gfortran" />
</or>
<cmdReturns name="gfortran -print-file-name=libgfortranbegin.a" />
<dirExists name="$$" />
</and>
</GFORTRANBEGIN_LIBDIR>
<GFORTRAN_VERSION>
<and>
<or>
<cmdReturns name="which gfortran" />
<fileExists name="/usr/local/bin/gfortran" />
</or>
<cmdReturns name="gfortran -dumpversion" />
</and>
</GFORTRAN_VERSION>
</locationFinder>
</config>
Accepted Answer
More Answers (0)
Categories
Find more on Fortran Source MEX Files 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!