Errors when using Matlab mex

I am using Matlab 2023a to call Fortran source file using mex. I use the following compiler for Fortran language compilation:

Intel oneAPI 2023 for Fortran with Microsoft Visual Studio 2022.

The code I used to compile is

mex ero_dep_fortran.f90 -output ero_dep_fortran

However, I got the following erros:

Error using mex C:\Users\40967\Desktop\Paper bank collapse and meander migration\Draft-version2\Code\ero_dep_fortran.lib �Ͷ��� C:\Users\40967\Desktop\Paper bank collapse and meander migration\Draft-version2\Code\ero_dep_fortran.exp ero_dep_fortran.obj : error LNK2019: �޷��������ⲿ���� NEW_EPOINTS_ASSIGNMENT���÷����ں��� MEXFUNCTION �б����� ero_dep_fortran.obj : error LNK2019: �޷��������ⲿ���� omp_get_wtime���÷����ں��� BANK_EROSION_CALCULATION_ENTRY �б����� C:\Users\40967\Desktop\Paper bank collapse and meander migration\�޸ĺ����\Draft-version2\Code\ero_dep_fortran.mexw64 : fatal error LNK1120: 2���޷��������ⲿ����

A lot of messy code in the error. I found the main problem maybe

ero_dep_fortran.obj : error LNK2019

but I do not know how to slove it...This code can be run in other computers with lower version of Matlab and Intel Parallel Studio XE, Microsoft Visual Studio.

Any suggestion is grateful....


  • I notice you are using a .f90 free format source file. Have you edited the MATLAB supplied compile file to get rid of the silly /fixed option on the $COMPFLAGS line yet? This forces the compiler to treat your file as a fixed format file which you don't want. Just delete that option from that file.

    E.g., On a PC you can check in the matlabroot\bin\win64\mexopts directory for an XML file that corresponds to your compiler. Then look for a line that resembles this:

     COMPFLAGS="/nologo /fpp /Qprec /fixed /MD /fp:source /assume:bscc $INCLUDE  $COMPDEFINES"

    Delete the /fixed option so that the line looks like this instead:

     COMPFLAGS="/nologo /fpp /Qprec /MD /fp:source /assume:bscc $INCLUDE  $COMPDEFINES"