Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MATLAB R2022a: MEX does not support the Fortran compilers specified in the official documentation #33

Closed
zaikunzhang opened this issue Mar 18, 2022 · 7 comments

Comments

@zaikunzhang
Copy link

zaikunzhang commented Mar 18, 2022

Hello!

Thank you very much for providing MATLAB on GitHub Actions. It is great that MATLAB R2022a is now made available!

According to the official documentation, MATLAB R2022a supports gfortan8.x as the Fortran compiler for MEX on Linux. However, according to my test on GitHub Actions, gfortran 8 fails to compile the official timestwo.F, the error message being

gfortran: error: unrecognized command line option ‘-fallow-argument-mismatch’;
  did you mean ‘-Wno-argument-mismatch’?

Nevertheless, gfortran 10 and 11 succeed, even though they are not supported officially.

I am not sure whether this comes from MATLAB R2022a itself, or from the setup of MATLAB on GitHub Actions. Thank you for having a look at it.

Update (20220319): The problem has been reproduced using "MATLAB Online". The official configuration of MATLAB Online (R2022a with gfortran 8.3.0) fails to run the following command, the error message being the same as above.

mex('-setup', '-v', 'FORTRAN'); mex('-v', fullfile(matlabroot, 'extern', 'examples', 'refbook', 'timestwo.F')); 

Therefore, this seems not a problem of GitHub Actions, but a bug of MATLAB R2022a.

Many thanks for everything!

Best regards,
Zaikun

@mcafaro
Copy link
Member

mcafaro commented Mar 18, 2022

Hi @zaikunzhang,

Can you try running your jobs again? R2022a was just posted.

Best,
Mark

@zaikunzhang
Copy link
Author

zaikunzhang commented Mar 18, 2022

Hello Mark @mcafaro ,

Thank you for your quick response!

I triggered my jobs again just now, and the results were still the same: MATLAB R2022a on Ubuntu 20.04 works with gfortran 10 and 11 but not 8 (or 9), which does not comply with the official documenation.

I am not sure what will happen on a local machine since I do not have a machine with MATLAB R2022a installed.

BTW, I am probably one of the first users who get to know that you have posted MATLAB R2022a on GitHub Actions, because I have MATLAB actions that run several times every day --- I woke up to find that they failed last night, and discovered that the failure was because MATLAB was updated and the default gfortran (gfortran 9, I think) of Ubuntu 20.04 on GitHub Actions did not work with MEX.

Thank you and your team again very much for everything!

Best regards,
Zaikun

@zaikunzhang
Copy link
Author

zaikunzhang commented Mar 21, 2022

Update: Why does the error occur?

According to the documentation 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&quot;$MATLABROOT/extern/include&quot; -I&quot;$MATLABROOT/simulink/include&quot;"
        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="&quot;$MATLABROOT/sys/os/$ARCH/orig/libstdc++.so.6&quot;"
        LINKLIBS="-Wl,-rpath-link,$MATLABROOT/bin/$ARCH  -L&quot;$MATLABROOT/sys/os/$ARCH/orig&quot; -L&quot;$MATLABROOT/bin/$ARCH&quot; $MWCPPLIB -lmx -lmex -lmat -lm -L&quot;$GFORTRAN_LIBDIR&quot; -lgfortran"
        LDOPTIMFLAGS="-O"
        LDDEBUGFLAGS="-g"
        MW_GLIBC_SHIM="$MW_GLIBC_SHIM"

        OBJEXT=".o"
        LDEXT=".mexa64"

        SETENV="FC=&quot;$FC&quot;
                FFLAGS=&quot;$FFLAGS $DEFINES&quot;
                FOPTIMFLAGS=&quot;$FOPTIMFLAGS&quot;
                FDEBUGFLAGS=&quot;$FDEBUGFLAGS&quot;
                LD=&quot;$FC&quot;
                LDFLAGS=&quot;$LDFLAGS $LDTYPE $LINKLIBS $LINKEXPORT&quot;
                LDDEBUGFLAGS=&quot;$LDDEBUGFLAGS&quot;">

        </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>
  1. 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&quot;$MATLABROOT/extern/include&quot; -I&quot;$MATLABROOT/simulink/include&quot;"
        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="&quot;$MATLABROOT/sys/os/$ARCH/orig/libstdc++.so.6&quot;"
        LINKLIBS="-Wl,-rpath-link,$MATLABROOT/bin/$ARCH -L&quot;$MATLABROOT/sys/os/$ARCH/orig&quot; -L&quot;$MATLABROOT/bin/$ARCH&quot; $MWCPPLIB -lmx -lmex -lmat -lm -L&quot;$GFORTRAN_LIBDIR&quot; -lgfortran -L&quot;$GFORTRANBEGIN_LIBDIR&quot; -lgfortranbegin"
        LDOPTIMFLAGS="-O"
        LDDEBUGFLAGS="-g"
        MW_GLIBC_SHIM="$MW_GLIBC_SHIM"

        OBJEXT=".o"
        LDEXT=".mexa64"

        SETENV="FC=&quot;$FC&quot;
                FFLAGS=&quot;$FFLAGS $DEFINES&quot;
                FOPTIMFLAGS=&quot;$FOPTIMFLAGS&quot;
                FDEBUGFLAGS=&quot;$FDEBUGFLAGS&quot;
                LD=&quot;$FC&quot;
                LDFLAGS=&quot;$LDFLAGS $LDTYPE $LINKLIBS $LINKEXPORT&quot;
                LDDEBUGFLAGS=&quot;$LDDEBUGFLAGS&quot;">

        </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>

@mcafaro
Copy link
Member

mcafaro commented Mar 22, 2022

Hi @zaikunzhang,

As you noted, this does not appear to be an issue with the MATLAB actions for GitHub but instead with the underlying MEX command. I have asked the MEX team about it and will post again when I have more information.

Best,
Mark

@zaikunzhang
Copy link
Author

zaikunzhang commented Mar 23, 2022

Hello Mark @mcafaro ,

Thank you very much for forwarding the issue to the MEX team.

Indeed, I have submitted a bug report (Case number 05433449), but the MathWorks colleague who handled it seemed quite indifferent about this obvious problem. I hope your forwarding will get some attention from the MEX team. I look forward to any updates.

Many thanks for everything!

Best regards,
Zaikun

@ssankarmw

This comment was marked as outdated.

@zaikunzhang
Copy link
Author

zaikunzhang commented Apr 6, 2022

Hello @ssankarmw !

Thank you very much for the detailed information.

I feel relaxed that the problem is confirmed as a bug rather than my delusion.

The MathWorks colleague who handled my bug report (Case number 05433449) was indifferent about the problem. He turned a deaf ear to me when he found I was using a trial license of MATLAB online. I explained to him in vain that I was not requesting any tech support --- the problem does not affect any of my projects --- but trying to uncover a problem in the hope of fixing it. I am not even sure whether he passed the report to the MEX team or not.

My post on MATLAB Answers got no luck to receive any attention either, although I am sure that there is MathWorks staff overlooking the forum.

I am closing this issue since it is not related to the set-up of GitHub-Actions MATLAB, which BTW is a life-changing facility that deserves a thousand thanks.

Thank you very much again. My best wishes for fixing the bug. I will be very happy to receive updates --- a response to my bug report, a comment on MATLAB Answers, or a message here.

Best regards,
Zaikun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants