1 year ago
#315046
Nuno
Does MATLAB R2022a support gfortran 8.x on Linux (as specified by the documentation)?
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 as follows.
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!
A bug report has been submitted to MathWorks, but no real response is received. It is a bit surprising to me how MathWorks handles this kind of bug (or documentation error).
I have posted the question on MATLAB Answers, but it seems that not many people are using MATLAB R2022a on Linux (yet).
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.
gfortran6.xml
located atfullfile(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>
gfortran.xml
located atfullfile(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>
linux
matlab
fortran
gfortran
mex
0 Answers
Your Answer