Error using mex, building with 'MinGW64 Compiler (FORTRAN)'
Show older comments
I am excited for the recent/native support of 'MinGW64 Compiler (FORTRAN)'. I successfully compiled the (fixed format) example, timestwo.F.
However, when I try to compile my (free format) program (which previously compile fine with the Intel compiler), I get the following error:
Error using mex
f951.exe: Warning: Nonexistent include directory 'C:\Program
Files\MATLAB\R2024a/simulink/include' [-Wmissing-include-dirs]
\MATLAB\toolbox\Fallterp111.f90:1:2:
#include "fintrf.h"
1
Warning: Illegal preprocessor directive
That is despite this being the identical first line of timestwo.F. I suspected that the /fixed flag might still be an issue, but I do not see it in \bin\win64\mexopts\mingw64_gfortran.xml, so I cannot delete it.
Any idea what is happening?
Here is the complete fortran program that gets the above error (note: I removed a couple calls to other subroutines to shorten this):
#include "fintrf.h"
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
! Declarations
implicit none
! mexFunction argument
mwPointer plhs(*), prhs(*)
integer*4 nlhs, nrhs
! Function declarations
mwSize mxGetM,mxGetN
mwpointer mxGetPr, mxCreateNumericArray, mxGetDimensions
double precision mxGetScalar
integer*4 mxClassIDFromClassName
! Pointers to input/output mxArrays
mwpointer x1_pr
mwpointer x1i_pr
mwpointer pf1_pr
mwpointer o1_pr
! Array information
mwSize nx1,nodes,e1
integer*4 myclassid
double precision, allocatable, dimension(:) :: x1,x1i
double precision, allocatable, dimension(:) :: pf1
double precision, allocatable, dimension(:) :: o1
! Load Inputs
! Grids
nx1 = mxGetN(prhs(1))
nodes = nx1
allocate(x1(nx1))
x1_pr = mxGetPr(prhs(1))
call mxCopyPtrToReal8(x1_pr,x1,nx1)
! Point to evaluate
e1 = mxGetM(prhs(2))
allocate(x1i(e1))
x1i_pr = mxGetPr(prhs(2))
call mxCopyPtrToReal8(x1i_pr,x1i,e1)
! Rules
allocate(pf1(nx1))
pf1_pr = mxGetPr(prhs(3))
call mxCopyPtrToReal8(pf1_pr,pf1,nodes)
!Create array for return argument
myclassid = mxClassIDFromClassName('double')
allocate(o1(e1))
plhs(1) = mxCreateNumericArray(1,e1,myclassid,0)
o1_pr = mxGetPr(plhs(1))
! Deallocate arrays
deallocate(x1)
deallocate(x1i)
deallocate(pf1)
deallocate(o1)
end subroutine mexFunction
Accepted Answer
More Answers (1)
James Tursa
on 22 Oct 2024
Edited: James Tursa
on 22 Oct 2024
FYI, you should never use literal constants in a Fortran API call, because you can't be sure whether the literal integer(4) or integer(8) will match up with the API function signature correctly. You can get away with this in a pass-by-value environment such as C/C++ where values automatically get promoted to the correct type, but you can't get away with this in a pass-by-reference environment such as Fortran using an implicit interface. Always create variables for passing API stuff in Fortran. E.g., since the signature for mxCreateNumericArray( ) is this:
mwPointer mxCreateNumericArray(ndim, dims, classid, ComplexFlag)
mwSize ndim
mwSize dims(ndim)
integer*4 classid, ComplexFlag
Your code should look something like this instead:
mwSize :: ndim = 1
integer*4 :: ComplexFlag = 0
:
plhs(1) = mxCreateNumericArray(ndim,e1,myclassid,ComplexFlag)
Sounds like TMW finally removed the silly /fixed option from the compiler flags, so that is good.
2 Comments
Nathaniel
on 22 Oct 2024
James Tursa
on 22 Oct 2024
You're very welcome ... and congrats on the dissertation!
Categories
Find more on MATLAB Support for MinGW-w64 C/C++ Compiler 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!