MATLAB gives “undefined reference” errors trying to use gfortran on Windowsgcc ignore casing of symbol names while linkingDoes symbol capitalization matter in object files with a linked dll?Cplex linking Error in Mex Command from MatlabMatlab Mex32 link error while compiling Felzenszwalb VOC on WindowsError in gfortran compilation : Undefined symbols for architecture x86_64compiling s-functions for matlaberror in unravel function for linking and decoding in huffman using matlabSimulink accelerator mode. Mex errorMatlab engine 2014a won't start under Windows 7 64 bit - missing a 2013a dllGfortran and Undefined reference to '__[module_name]_MOD_[function_name]'Calling MATLAB Engine error: libeng.dll is missing from your computerLinking error in gfortran with devtoolset-6
Should I be an author on another PhD student's paper if I went to their meetings and gave advice?
Is there a pattern for handling conflicting function parameters?
Avoiding dust scattering when you drill
Why has Speaker Pelosi been so hesitant to impeach President Trump?
Is there anything on the ISS that would be destroyed if that object were returned to Earth?
What are one's options when facing religious discrimination at the airport?
Airport Security - advanced check, 4th amendment breach
What is the point of impeaching Trump?
What does "execute a hard copy" mean?
Job interview by video at home and privacy concerns
What is the meaning of first flight and introduction in aircraft production?
Is spot metering just an EV compensation?
IEEE 754 square root with Newton-Raphson
Why most footers have a background color as a divider of section?
French license plates
As a team leader is it appropriate to bring in fundraiser candy?
Duck, duck, gone!
Knights and Knaves: What does C say?
Are there types of animals that can't make the trip to space? (physiologically)
Wondering why they used ultrafast diodes in a 50 or 60Hz bridge?
Did Tolkien ever write about a Heaven or Hell for Men?
How to identify whether a publisher is genuine or not?
Sending mail to the Professor for PhD, after seeing his tweet
Phonetic distortion when words are borrowed among languages
MATLAB gives “undefined reference” errors trying to use gfortran on Windows
gcc ignore casing of symbol names while linkingDoes symbol capitalization matter in object files with a linked dll?Cplex linking Error in Mex Command from MatlabMatlab Mex32 link error while compiling Felzenszwalb VOC on WindowsError in gfortran compilation : Undefined symbols for architecture x86_64compiling s-functions for matlaberror in unravel function for linking and decoding in huffman using matlabSimulink accelerator mode. Mex errorMatlab engine 2014a won't start under Windows 7 64 bit - missing a 2013a dllGfortran and Undefined reference to '__[module_name]_MOD_[function_name]'Calling MATLAB Engine error: libeng.dll is missing from your computerLinking error in gfortran with devtoolset-6
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
I'm trying to use MinGW gfortran with MATLAB R2019a on Windows 10 by writing a mexopts XML file based on existing XML files. I have cygwin installed with MinGW gcc, and I've been able to run mex -setup
referencing the XML file successfully. When I try to compile the timestwo.F file to test the setup (using mex -R2018a timestwo.F90
), I get a bunch of errors:
Building with 'cygwin MinGW64 Compiler (Fortran)'.
C:cygwin64binx86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:cygwin64homeuserMATLABtimestwo.F90" -o C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o
f951: Warning: Nonexistent include directory ‘C:Program FilesMATLABR2019asimulinkinclude’ [-Wmissing-include-dirs]
C:cygwin64binx86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:Program FilesMATLABR2019aexternversionfortran_mexapi_version.F" -o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o
f951: Warning: Nonexistent include directory ‘C:Program FilesMATLABR2019asimulinkinclude’ [-Wmissing-include-dirs]
C:cygwin64binx86_64-w64-mingw32-gfortran -pthread -shared -O3 -mtune=native -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fortran_exportsmexfileversion.map" C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o -Wl,-L"C:Program FilesMATLABR2019aexternlibwin64mingw64" -llibmx -llibmex -llibmat -lm -L"C:cygwin64libgccx86_64-w64-mingw327.4.0" -lgfortran -o timestwo.mexw64
Error using mex
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x47): undefined reference to
`mxisnumeric800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x6a): undefined reference to
`mexerrmsgidandtxt800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x72): undefined reference to
`mxgetdoubles800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x7d): undefined reference to `mxgetm800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x8c): undefined reference to `mxgetn800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0xa6): undefined reference to
`mxcopyptrtoreal8800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0xba): undefined reference to
`mxcreatedoublematrix800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0xc4): undefined reference to
`mxgetdoubles800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0xe5): undefined reference to
`mxcopyreal8toptr800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x10d): undefined reference to
`mexerrmsgidandtxt800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x13b): undefined reference to
`mexerrmsgidandtxt800_'
collect2: error: ld returned 1 exit status
Here's my source:
! Gateway routine
#include "fintrf.h"
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
implicit none
mwPointer plhs(*), prhs(*)
integer nlhs, nrhs
! Declarations
mwPointer mxGetDoubles
mwPointer mxCreateDoubleMatrix
integer mxIsNumeric
mwPointer mxGetM, mxGetN
mwPointer x_ptr, y_ptr
mwPointer mrows, ncols
mwSize size
! Declare variables for computational routine
real*8 x_input, y_output
! Make sure input is valid
if(nrhs /= 1) then
call mexErrMsgIdAndTxt ('MATLAB:timestwo:nInput', &
'One input required.')
elseif(nlhs > 1) then
call mexErrMsgIdAndTxt ('MATLAB:timestwo:nOutput', &
'Too many output arguments.')
endif
if(mxIsNumeric(prhs(1)) == 0) then
call mexErrMsgIdAndTxt ('MATLAB:timestwo:NonNumeric', &
'Input must be a number.')
endif
! Read input array
x_ptr = mxGetDoubles(prhs(1))
! Get size of array
mrows = mxGetM(prhs(1))
ncols = mxGetN(prhs(1))
size = mrows*ncols
! Create a Fortran array from the input
call mxCopyPtrToReal8(x_ptr,x_input,size)
! Prepare a matrix for output
plhs(1) = mxCreateDoubleMatrix(mrows,ncols,0)
y_ptr = mxGetDoubles(plhs(1))
call timestwo(y_output, x_input)
! copy results to output argument
call mxCopyReal8ToPtr(y_output,y_ptr,size)
return
end
subroutine timestwo(y_output, x_input)
real*8 x_input, y_output
y_output = 2.0*x_input
return
end
The output is the same if I try with the included matlabrootexternexamplesrefbooktimestwo.F
fixed-form version.
My options file details (first part of output from mex -v -R2018a timestwo.F90
)
Compiler location: C:cygwin64
Options file: C:UsersuserAppDataRoamingMathWorksMATLABR2019amex_FORTRAN_win64.xml
CMDLINE2 : C:cygwin64binx86_64-w64-mingw32-gfortran -pthread -shared -O3 -mtune=native -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fortran_exportsmexfileversion.map" C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o -Wl,-L"C:Program FilesMATLABR2019aexternlibwin64mingw64" -llibmx -llibmex -llibmat -lm -L"C:cygwin64libgccx86_64-w64-mingw327.4.0" -lgfortran -o timestwo.mexw64
FC : C:cygwin64binx86_64-w64-mingw32-gfortran
DEFINES : -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD
FFLAGS : -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer
INCLUDE : -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64"
FOPTIMFLAGS : -O3 -mtune=native
FDEBUGFLAGS : -g -Wall
LDF : C:cygwin64binx86_64-w64-mingw32-gfortran
LDFLAGS : -pthread
LDTYPE : -shared
LINKEXPORT : -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fexport.map"
LINKEXPORTVER : -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fortran_exportsmexfileversion.map"
LINKLIBS : -Wl,-L"C:Program FilesMATLABR2019aexternlibwin64mingw64" -llibmx -llibmex -llibmat -lm -L"C:cygwin64libgccx86_64-w64-mingw327.4.0" -lgfortran
LDOPTIMFLAGS : -O3 -mtune=native
LDDEBUGFLAGS : -g -Wall
OBJEXT : .o
LDEXT : .mexw64
SETENV : set COMPILER=C:cygwin64binx86_64-w64-mingw32-gfortran
set COMPFLAGS=-fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD
set OPTIMFLAGS=-O3 -mtune=native
set DEBUGFLAGS=-g -Wall
set LINKER=C:cygwin64binx86_64-w64-mingw32-gfortran
set LINKFLAGS=-pthread
set LINKDEBUGFLAGS=-pthread -shared -Wl,-L"C:Program FilesMATLABR2019aexternlibwin64mingw64" -llibmx -llibmex -llibmat -lm -L"C:cygwin64libgccx86_64-w64-mingw327.4.0" -lgfortran -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fexport.map"
set LDDEBUGFLAGS=-g -Wall
set NAME_OUTPUT=-o "%OUTDIR%%MEX_NAME%%MEX_EXT%%"
CYGWINROOT : C:cygwin64
MATLABROOT : C:Program FilesMATLABR2019a
ARCH : win64
SRC : "C:cygwin64homeuserMATLABtimestwo.F90";"C:Program FilesMATLABR2019aexternversionfortran_mexapi_version.F"
OBJ : C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o;C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o
OBJS : C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o
SRCROOT : C:cygwin64homeuserMATLABtimestwo
DEF : C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.def
EXP : "timestwo.exp"
LIB : "timestwo.lib"
EXE : timestwo.mexw64
ILK : "timestwo.ilk"
MANIFEST : "timestwo.mexw64.manifest"
TEMPNAME : timestwo
EXEDIR :
EXENAME : timestwo
OPTIM : -O3 -mtune=native
LINKOPTIM : -O3 -mtune=native
CMDLINE1_0 : C:cygwin64binx86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:cygwin64homeuserMATLABtimestwo.F90" -o C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o
CMDLINE1_1 : C:cygwin64binx86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:Program FilesMATLABR2019aexternversionfortran_mexapi_version.F" -o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o
It seems like the mex-specific types like mwPointer defined in fintrf.h aren't being defined, even though I've included its location. Why are these types not recognized?
matlab fortran gfortran mex
add a comment
|
I'm trying to use MinGW gfortran with MATLAB R2019a on Windows 10 by writing a mexopts XML file based on existing XML files. I have cygwin installed with MinGW gcc, and I've been able to run mex -setup
referencing the XML file successfully. When I try to compile the timestwo.F file to test the setup (using mex -R2018a timestwo.F90
), I get a bunch of errors:
Building with 'cygwin MinGW64 Compiler (Fortran)'.
C:cygwin64binx86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:cygwin64homeuserMATLABtimestwo.F90" -o C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o
f951: Warning: Nonexistent include directory ‘C:Program FilesMATLABR2019asimulinkinclude’ [-Wmissing-include-dirs]
C:cygwin64binx86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:Program FilesMATLABR2019aexternversionfortran_mexapi_version.F" -o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o
f951: Warning: Nonexistent include directory ‘C:Program FilesMATLABR2019asimulinkinclude’ [-Wmissing-include-dirs]
C:cygwin64binx86_64-w64-mingw32-gfortran -pthread -shared -O3 -mtune=native -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fortran_exportsmexfileversion.map" C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o -Wl,-L"C:Program FilesMATLABR2019aexternlibwin64mingw64" -llibmx -llibmex -llibmat -lm -L"C:cygwin64libgccx86_64-w64-mingw327.4.0" -lgfortran -o timestwo.mexw64
Error using mex
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x47): undefined reference to
`mxisnumeric800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x6a): undefined reference to
`mexerrmsgidandtxt800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x72): undefined reference to
`mxgetdoubles800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x7d): undefined reference to `mxgetm800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x8c): undefined reference to `mxgetn800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0xa6): undefined reference to
`mxcopyptrtoreal8800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0xba): undefined reference to
`mxcreatedoublematrix800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0xc4): undefined reference to
`mxgetdoubles800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0xe5): undefined reference to
`mxcopyreal8toptr800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x10d): undefined reference to
`mexerrmsgidandtxt800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x13b): undefined reference to
`mexerrmsgidandtxt800_'
collect2: error: ld returned 1 exit status
Here's my source:
! Gateway routine
#include "fintrf.h"
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
implicit none
mwPointer plhs(*), prhs(*)
integer nlhs, nrhs
! Declarations
mwPointer mxGetDoubles
mwPointer mxCreateDoubleMatrix
integer mxIsNumeric
mwPointer mxGetM, mxGetN
mwPointer x_ptr, y_ptr
mwPointer mrows, ncols
mwSize size
! Declare variables for computational routine
real*8 x_input, y_output
! Make sure input is valid
if(nrhs /= 1) then
call mexErrMsgIdAndTxt ('MATLAB:timestwo:nInput', &
'One input required.')
elseif(nlhs > 1) then
call mexErrMsgIdAndTxt ('MATLAB:timestwo:nOutput', &
'Too many output arguments.')
endif
if(mxIsNumeric(prhs(1)) == 0) then
call mexErrMsgIdAndTxt ('MATLAB:timestwo:NonNumeric', &
'Input must be a number.')
endif
! Read input array
x_ptr = mxGetDoubles(prhs(1))
! Get size of array
mrows = mxGetM(prhs(1))
ncols = mxGetN(prhs(1))
size = mrows*ncols
! Create a Fortran array from the input
call mxCopyPtrToReal8(x_ptr,x_input,size)
! Prepare a matrix for output
plhs(1) = mxCreateDoubleMatrix(mrows,ncols,0)
y_ptr = mxGetDoubles(plhs(1))
call timestwo(y_output, x_input)
! copy results to output argument
call mxCopyReal8ToPtr(y_output,y_ptr,size)
return
end
subroutine timestwo(y_output, x_input)
real*8 x_input, y_output
y_output = 2.0*x_input
return
end
The output is the same if I try with the included matlabrootexternexamplesrefbooktimestwo.F
fixed-form version.
My options file details (first part of output from mex -v -R2018a timestwo.F90
)
Compiler location: C:cygwin64
Options file: C:UsersuserAppDataRoamingMathWorksMATLABR2019amex_FORTRAN_win64.xml
CMDLINE2 : C:cygwin64binx86_64-w64-mingw32-gfortran -pthread -shared -O3 -mtune=native -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fortran_exportsmexfileversion.map" C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o -Wl,-L"C:Program FilesMATLABR2019aexternlibwin64mingw64" -llibmx -llibmex -llibmat -lm -L"C:cygwin64libgccx86_64-w64-mingw327.4.0" -lgfortran -o timestwo.mexw64
FC : C:cygwin64binx86_64-w64-mingw32-gfortran
DEFINES : -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD
FFLAGS : -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer
INCLUDE : -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64"
FOPTIMFLAGS : -O3 -mtune=native
FDEBUGFLAGS : -g -Wall
LDF : C:cygwin64binx86_64-w64-mingw32-gfortran
LDFLAGS : -pthread
LDTYPE : -shared
LINKEXPORT : -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fexport.map"
LINKEXPORTVER : -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fortran_exportsmexfileversion.map"
LINKLIBS : -Wl,-L"C:Program FilesMATLABR2019aexternlibwin64mingw64" -llibmx -llibmex -llibmat -lm -L"C:cygwin64libgccx86_64-w64-mingw327.4.0" -lgfortran
LDOPTIMFLAGS : -O3 -mtune=native
LDDEBUGFLAGS : -g -Wall
OBJEXT : .o
LDEXT : .mexw64
SETENV : set COMPILER=C:cygwin64binx86_64-w64-mingw32-gfortran
set COMPFLAGS=-fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD
set OPTIMFLAGS=-O3 -mtune=native
set DEBUGFLAGS=-g -Wall
set LINKER=C:cygwin64binx86_64-w64-mingw32-gfortran
set LINKFLAGS=-pthread
set LINKDEBUGFLAGS=-pthread -shared -Wl,-L"C:Program FilesMATLABR2019aexternlibwin64mingw64" -llibmx -llibmex -llibmat -lm -L"C:cygwin64libgccx86_64-w64-mingw327.4.0" -lgfortran -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fexport.map"
set LDDEBUGFLAGS=-g -Wall
set NAME_OUTPUT=-o "%OUTDIR%%MEX_NAME%%MEX_EXT%%"
CYGWINROOT : C:cygwin64
MATLABROOT : C:Program FilesMATLABR2019a
ARCH : win64
SRC : "C:cygwin64homeuserMATLABtimestwo.F90";"C:Program FilesMATLABR2019aexternversionfortran_mexapi_version.F"
OBJ : C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o;C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o
OBJS : C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o
SRCROOT : C:cygwin64homeuserMATLABtimestwo
DEF : C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.def
EXP : "timestwo.exp"
LIB : "timestwo.lib"
EXE : timestwo.mexw64
ILK : "timestwo.ilk"
MANIFEST : "timestwo.mexw64.manifest"
TEMPNAME : timestwo
EXEDIR :
EXENAME : timestwo
OPTIM : -O3 -mtune=native
LINKOPTIM : -O3 -mtune=native
CMDLINE1_0 : C:cygwin64binx86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:cygwin64homeuserMATLABtimestwo.F90" -o C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o
CMDLINE1_1 : C:cygwin64binx86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:Program FilesMATLABR2019aexternversionfortran_mexapi_version.F" -o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o
It seems like the mex-specific types like mwPointer defined in fintrf.h aren't being defined, even though I've included its location. Why are these types not recognized?
matlab fortran gfortran mex
1
Are you sure you should declare the MATLAB functions?mwPointer mxGetDoubles
. Aren't those defined in the header file you include? These functions should likely be declared asextern C
(or however you do that in Fortran), which would fix your capitalization issue.
– Cris Luengo
Apr 3 at 16:46
This is how MathWorks specifies the Fortran test file, so that was how I wrote my copy. mxGetDoubles is defined in the header file, but if I remove the declaration, I getError: Function ‘mxgetdoubles800’ at (1) has no IMPLICIT type
– zaen
Apr 3 at 16:51
I see. Fortran is a weird language... :) -- Did you try compiling one of the demos that come with MATLAB?mex([matlabroot '/extern/examples/refbook/timestwo.F'])
.
– Cris Luengo
Apr 3 at 17:03
Yes, those fail as well. They succeed on Linux, and I think I've found the reason. The Linux libraries export symbols in a gfortran-compatible way, e.g. mxisnumeric800_. The underscore can be removed with -fno-underscoring, but the gfortran developers didn't include the -fsymbol-case-upper option from g77. That, I'm pretty sure, is the problem; gfortran forces symbols to be lowercase, while the Intel compiler goes for uppercase.
– zaen
Apr 3 at 17:10
Ah, that must be it. MATLAB supports the Intel Fortran compiler only on Windows.
– Cris Luengo
Apr 3 at 17:15
add a comment
|
I'm trying to use MinGW gfortran with MATLAB R2019a on Windows 10 by writing a mexopts XML file based on existing XML files. I have cygwin installed with MinGW gcc, and I've been able to run mex -setup
referencing the XML file successfully. When I try to compile the timestwo.F file to test the setup (using mex -R2018a timestwo.F90
), I get a bunch of errors:
Building with 'cygwin MinGW64 Compiler (Fortran)'.
C:cygwin64binx86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:cygwin64homeuserMATLABtimestwo.F90" -o C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o
f951: Warning: Nonexistent include directory ‘C:Program FilesMATLABR2019asimulinkinclude’ [-Wmissing-include-dirs]
C:cygwin64binx86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:Program FilesMATLABR2019aexternversionfortran_mexapi_version.F" -o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o
f951: Warning: Nonexistent include directory ‘C:Program FilesMATLABR2019asimulinkinclude’ [-Wmissing-include-dirs]
C:cygwin64binx86_64-w64-mingw32-gfortran -pthread -shared -O3 -mtune=native -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fortran_exportsmexfileversion.map" C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o -Wl,-L"C:Program FilesMATLABR2019aexternlibwin64mingw64" -llibmx -llibmex -llibmat -lm -L"C:cygwin64libgccx86_64-w64-mingw327.4.0" -lgfortran -o timestwo.mexw64
Error using mex
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x47): undefined reference to
`mxisnumeric800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x6a): undefined reference to
`mexerrmsgidandtxt800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x72): undefined reference to
`mxgetdoubles800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x7d): undefined reference to `mxgetm800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x8c): undefined reference to `mxgetn800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0xa6): undefined reference to
`mxcopyptrtoreal8800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0xba): undefined reference to
`mxcreatedoublematrix800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0xc4): undefined reference to
`mxgetdoubles800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0xe5): undefined reference to
`mxcopyreal8toptr800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x10d): undefined reference to
`mexerrmsgidandtxt800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x13b): undefined reference to
`mexerrmsgidandtxt800_'
collect2: error: ld returned 1 exit status
Here's my source:
! Gateway routine
#include "fintrf.h"
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
implicit none
mwPointer plhs(*), prhs(*)
integer nlhs, nrhs
! Declarations
mwPointer mxGetDoubles
mwPointer mxCreateDoubleMatrix
integer mxIsNumeric
mwPointer mxGetM, mxGetN
mwPointer x_ptr, y_ptr
mwPointer mrows, ncols
mwSize size
! Declare variables for computational routine
real*8 x_input, y_output
! Make sure input is valid
if(nrhs /= 1) then
call mexErrMsgIdAndTxt ('MATLAB:timestwo:nInput', &
'One input required.')
elseif(nlhs > 1) then
call mexErrMsgIdAndTxt ('MATLAB:timestwo:nOutput', &
'Too many output arguments.')
endif
if(mxIsNumeric(prhs(1)) == 0) then
call mexErrMsgIdAndTxt ('MATLAB:timestwo:NonNumeric', &
'Input must be a number.')
endif
! Read input array
x_ptr = mxGetDoubles(prhs(1))
! Get size of array
mrows = mxGetM(prhs(1))
ncols = mxGetN(prhs(1))
size = mrows*ncols
! Create a Fortran array from the input
call mxCopyPtrToReal8(x_ptr,x_input,size)
! Prepare a matrix for output
plhs(1) = mxCreateDoubleMatrix(mrows,ncols,0)
y_ptr = mxGetDoubles(plhs(1))
call timestwo(y_output, x_input)
! copy results to output argument
call mxCopyReal8ToPtr(y_output,y_ptr,size)
return
end
subroutine timestwo(y_output, x_input)
real*8 x_input, y_output
y_output = 2.0*x_input
return
end
The output is the same if I try with the included matlabrootexternexamplesrefbooktimestwo.F
fixed-form version.
My options file details (first part of output from mex -v -R2018a timestwo.F90
)
Compiler location: C:cygwin64
Options file: C:UsersuserAppDataRoamingMathWorksMATLABR2019amex_FORTRAN_win64.xml
CMDLINE2 : C:cygwin64binx86_64-w64-mingw32-gfortran -pthread -shared -O3 -mtune=native -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fortran_exportsmexfileversion.map" C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o -Wl,-L"C:Program FilesMATLABR2019aexternlibwin64mingw64" -llibmx -llibmex -llibmat -lm -L"C:cygwin64libgccx86_64-w64-mingw327.4.0" -lgfortran -o timestwo.mexw64
FC : C:cygwin64binx86_64-w64-mingw32-gfortran
DEFINES : -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD
FFLAGS : -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer
INCLUDE : -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64"
FOPTIMFLAGS : -O3 -mtune=native
FDEBUGFLAGS : -g -Wall
LDF : C:cygwin64binx86_64-w64-mingw32-gfortran
LDFLAGS : -pthread
LDTYPE : -shared
LINKEXPORT : -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fexport.map"
LINKEXPORTVER : -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fortran_exportsmexfileversion.map"
LINKLIBS : -Wl,-L"C:Program FilesMATLABR2019aexternlibwin64mingw64" -llibmx -llibmex -llibmat -lm -L"C:cygwin64libgccx86_64-w64-mingw327.4.0" -lgfortran
LDOPTIMFLAGS : -O3 -mtune=native
LDDEBUGFLAGS : -g -Wall
OBJEXT : .o
LDEXT : .mexw64
SETENV : set COMPILER=C:cygwin64binx86_64-w64-mingw32-gfortran
set COMPFLAGS=-fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD
set OPTIMFLAGS=-O3 -mtune=native
set DEBUGFLAGS=-g -Wall
set LINKER=C:cygwin64binx86_64-w64-mingw32-gfortran
set LINKFLAGS=-pthread
set LINKDEBUGFLAGS=-pthread -shared -Wl,-L"C:Program FilesMATLABR2019aexternlibwin64mingw64" -llibmx -llibmex -llibmat -lm -L"C:cygwin64libgccx86_64-w64-mingw327.4.0" -lgfortran -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fexport.map"
set LDDEBUGFLAGS=-g -Wall
set NAME_OUTPUT=-o "%OUTDIR%%MEX_NAME%%MEX_EXT%%"
CYGWINROOT : C:cygwin64
MATLABROOT : C:Program FilesMATLABR2019a
ARCH : win64
SRC : "C:cygwin64homeuserMATLABtimestwo.F90";"C:Program FilesMATLABR2019aexternversionfortran_mexapi_version.F"
OBJ : C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o;C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o
OBJS : C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o
SRCROOT : C:cygwin64homeuserMATLABtimestwo
DEF : C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.def
EXP : "timestwo.exp"
LIB : "timestwo.lib"
EXE : timestwo.mexw64
ILK : "timestwo.ilk"
MANIFEST : "timestwo.mexw64.manifest"
TEMPNAME : timestwo
EXEDIR :
EXENAME : timestwo
OPTIM : -O3 -mtune=native
LINKOPTIM : -O3 -mtune=native
CMDLINE1_0 : C:cygwin64binx86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:cygwin64homeuserMATLABtimestwo.F90" -o C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o
CMDLINE1_1 : C:cygwin64binx86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:Program FilesMATLABR2019aexternversionfortran_mexapi_version.F" -o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o
It seems like the mex-specific types like mwPointer defined in fintrf.h aren't being defined, even though I've included its location. Why are these types not recognized?
matlab fortran gfortran mex
I'm trying to use MinGW gfortran with MATLAB R2019a on Windows 10 by writing a mexopts XML file based on existing XML files. I have cygwin installed with MinGW gcc, and I've been able to run mex -setup
referencing the XML file successfully. When I try to compile the timestwo.F file to test the setup (using mex -R2018a timestwo.F90
), I get a bunch of errors:
Building with 'cygwin MinGW64 Compiler (Fortran)'.
C:cygwin64binx86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:cygwin64homeuserMATLABtimestwo.F90" -o C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o
f951: Warning: Nonexistent include directory ‘C:Program FilesMATLABR2019asimulinkinclude’ [-Wmissing-include-dirs]
C:cygwin64binx86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:Program FilesMATLABR2019aexternversionfortran_mexapi_version.F" -o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o
f951: Warning: Nonexistent include directory ‘C:Program FilesMATLABR2019asimulinkinclude’ [-Wmissing-include-dirs]
C:cygwin64binx86_64-w64-mingw32-gfortran -pthread -shared -O3 -mtune=native -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fortran_exportsmexfileversion.map" C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o -Wl,-L"C:Program FilesMATLABR2019aexternlibwin64mingw64" -llibmx -llibmex -llibmat -lm -L"C:cygwin64libgccx86_64-w64-mingw327.4.0" -lgfortran -o timestwo.mexw64
Error using mex
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x47): undefined reference to
`mxisnumeric800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x6a): undefined reference to
`mexerrmsgidandtxt800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x72): undefined reference to
`mxgetdoubles800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x7d): undefined reference to `mxgetm800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x8c): undefined reference to `mxgetn800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0xa6): undefined reference to
`mxcopyptrtoreal8800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0xba): undefined reference to
`mxcreatedoublematrix800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0xc4): undefined reference to
`mxgetdoubles800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0xe5): undefined reference to
`mxcopyreal8toptr800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x10d): undefined reference to
`mexerrmsgidandtxt800_'
C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o:timestwo.F90:(.text+0x13b): undefined reference to
`mexerrmsgidandtxt800_'
collect2: error: ld returned 1 exit status
Here's my source:
! Gateway routine
#include "fintrf.h"
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
implicit none
mwPointer plhs(*), prhs(*)
integer nlhs, nrhs
! Declarations
mwPointer mxGetDoubles
mwPointer mxCreateDoubleMatrix
integer mxIsNumeric
mwPointer mxGetM, mxGetN
mwPointer x_ptr, y_ptr
mwPointer mrows, ncols
mwSize size
! Declare variables for computational routine
real*8 x_input, y_output
! Make sure input is valid
if(nrhs /= 1) then
call mexErrMsgIdAndTxt ('MATLAB:timestwo:nInput', &
'One input required.')
elseif(nlhs > 1) then
call mexErrMsgIdAndTxt ('MATLAB:timestwo:nOutput', &
'Too many output arguments.')
endif
if(mxIsNumeric(prhs(1)) == 0) then
call mexErrMsgIdAndTxt ('MATLAB:timestwo:NonNumeric', &
'Input must be a number.')
endif
! Read input array
x_ptr = mxGetDoubles(prhs(1))
! Get size of array
mrows = mxGetM(prhs(1))
ncols = mxGetN(prhs(1))
size = mrows*ncols
! Create a Fortran array from the input
call mxCopyPtrToReal8(x_ptr,x_input,size)
! Prepare a matrix for output
plhs(1) = mxCreateDoubleMatrix(mrows,ncols,0)
y_ptr = mxGetDoubles(plhs(1))
call timestwo(y_output, x_input)
! copy results to output argument
call mxCopyReal8ToPtr(y_output,y_ptr,size)
return
end
subroutine timestwo(y_output, x_input)
real*8 x_input, y_output
y_output = 2.0*x_input
return
end
The output is the same if I try with the included matlabrootexternexamplesrefbooktimestwo.F
fixed-form version.
My options file details (first part of output from mex -v -R2018a timestwo.F90
)
Compiler location: C:cygwin64
Options file: C:UsersuserAppDataRoamingMathWorksMATLABR2019amex_FORTRAN_win64.xml
CMDLINE2 : C:cygwin64binx86_64-w64-mingw32-gfortran -pthread -shared -O3 -mtune=native -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fortran_exportsmexfileversion.map" C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o -Wl,-L"C:Program FilesMATLABR2019aexternlibwin64mingw64" -llibmx -llibmex -llibmat -lm -L"C:cygwin64libgccx86_64-w64-mingw327.4.0" -lgfortran -o timestwo.mexw64
FC : C:cygwin64binx86_64-w64-mingw32-gfortran
DEFINES : -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD
FFLAGS : -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer
INCLUDE : -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64"
FOPTIMFLAGS : -O3 -mtune=native
FDEBUGFLAGS : -g -Wall
LDF : C:cygwin64binx86_64-w64-mingw32-gfortran
LDFLAGS : -pthread
LDTYPE : -shared
LINKEXPORT : -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fexport.map"
LINKEXPORTVER : -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fortran_exportsmexfileversion.map"
LINKLIBS : -Wl,-L"C:Program FilesMATLABR2019aexternlibwin64mingw64" -llibmx -llibmex -llibmat -lm -L"C:cygwin64libgccx86_64-w64-mingw327.4.0" -lgfortran
LDOPTIMFLAGS : -O3 -mtune=native
LDDEBUGFLAGS : -g -Wall
OBJEXT : .o
LDEXT : .mexw64
SETENV : set COMPILER=C:cygwin64binx86_64-w64-mingw32-gfortran
set COMPFLAGS=-fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD
set OPTIMFLAGS=-O3 -mtune=native
set DEBUGFLAGS=-g -Wall
set LINKER=C:cygwin64binx86_64-w64-mingw32-gfortran
set LINKFLAGS=-pthread
set LINKDEBUGFLAGS=-pthread -shared -Wl,-L"C:Program FilesMATLABR2019aexternlibwin64mingw64" -llibmx -llibmex -llibmat -lm -L"C:cygwin64libgccx86_64-w64-mingw327.4.0" -lgfortran -Wl,--version-script,"C:Program FilesMATLABR2019aexternlibwin64mingw64fexport.map"
set LDDEBUGFLAGS=-g -Wall
set NAME_OUTPUT=-o "%OUTDIR%%MEX_NAME%%MEX_EXT%%"
CYGWINROOT : C:cygwin64
MATLABROOT : C:Program FilesMATLABR2019a
ARCH : win64
SRC : "C:cygwin64homeuserMATLABtimestwo.F90";"C:Program FilesMATLABR2019aexternversionfortran_mexapi_version.F"
OBJ : C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o;C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o
OBJS : C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o
SRCROOT : C:cygwin64homeuserMATLABtimestwo
DEF : C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.def
EXP : "timestwo.exp"
LIB : "timestwo.lib"
EXE : timestwo.mexw64
ILK : "timestwo.ilk"
MANIFEST : "timestwo.mexw64.manifest"
TEMPNAME : timestwo
EXEDIR :
EXENAME : timestwo
OPTIM : -O3 -mtune=native
LINKOPTIM : -O3 -mtune=native
CMDLINE1_0 : C:cygwin64binx86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:cygwin64homeuserMATLABtimestwo.F90" -o C:UsersuserAppDataLocalTempmex_62691295256641_4248timestwo.o
CMDLINE1_1 : C:cygwin64binx86_64-w64-mingw32-gfortran -c -DMX_COMPAT_64 -DMATLAB_MEXCMD_RELEASE=R2018a -DUSE_MEX_CMD -I"C:Program FilesMATLABR2019aexterninclude" -I"C:Program FilesMATLABR2019asimulinkinclude" -I"C:Program FilesMATLABR2019aexternlibwin64mingw64" -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer -O3 -mtune=native "C:Program FilesMATLABR2019aexternversionfortran_mexapi_version.F" -o C:UsersuserAppDataLocalTempmex_62691295256641_4248fortran_mexapi_version.o
It seems like the mex-specific types like mwPointer defined in fintrf.h aren't being defined, even though I've included its location. Why are these types not recognized?
matlab fortran gfortran mex
matlab fortran gfortran mex
asked Mar 28 at 20:54
zaenzaen
1741 silver badge9 bronze badges
1741 silver badge9 bronze badges
1
Are you sure you should declare the MATLAB functions?mwPointer mxGetDoubles
. Aren't those defined in the header file you include? These functions should likely be declared asextern C
(or however you do that in Fortran), which would fix your capitalization issue.
– Cris Luengo
Apr 3 at 16:46
This is how MathWorks specifies the Fortran test file, so that was how I wrote my copy. mxGetDoubles is defined in the header file, but if I remove the declaration, I getError: Function ‘mxgetdoubles800’ at (1) has no IMPLICIT type
– zaen
Apr 3 at 16:51
I see. Fortran is a weird language... :) -- Did you try compiling one of the demos that come with MATLAB?mex([matlabroot '/extern/examples/refbook/timestwo.F'])
.
– Cris Luengo
Apr 3 at 17:03
Yes, those fail as well. They succeed on Linux, and I think I've found the reason. The Linux libraries export symbols in a gfortran-compatible way, e.g. mxisnumeric800_. The underscore can be removed with -fno-underscoring, but the gfortran developers didn't include the -fsymbol-case-upper option from g77. That, I'm pretty sure, is the problem; gfortran forces symbols to be lowercase, while the Intel compiler goes for uppercase.
– zaen
Apr 3 at 17:10
Ah, that must be it. MATLAB supports the Intel Fortran compiler only on Windows.
– Cris Luengo
Apr 3 at 17:15
add a comment
|
1
Are you sure you should declare the MATLAB functions?mwPointer mxGetDoubles
. Aren't those defined in the header file you include? These functions should likely be declared asextern C
(or however you do that in Fortran), which would fix your capitalization issue.
– Cris Luengo
Apr 3 at 16:46
This is how MathWorks specifies the Fortran test file, so that was how I wrote my copy. mxGetDoubles is defined in the header file, but if I remove the declaration, I getError: Function ‘mxgetdoubles800’ at (1) has no IMPLICIT type
– zaen
Apr 3 at 16:51
I see. Fortran is a weird language... :) -- Did you try compiling one of the demos that come with MATLAB?mex([matlabroot '/extern/examples/refbook/timestwo.F'])
.
– Cris Luengo
Apr 3 at 17:03
Yes, those fail as well. They succeed on Linux, and I think I've found the reason. The Linux libraries export symbols in a gfortran-compatible way, e.g. mxisnumeric800_. The underscore can be removed with -fno-underscoring, but the gfortran developers didn't include the -fsymbol-case-upper option from g77. That, I'm pretty sure, is the problem; gfortran forces symbols to be lowercase, while the Intel compiler goes for uppercase.
– zaen
Apr 3 at 17:10
Ah, that must be it. MATLAB supports the Intel Fortran compiler only on Windows.
– Cris Luengo
Apr 3 at 17:15
1
1
Are you sure you should declare the MATLAB functions?
mwPointer mxGetDoubles
. Aren't those defined in the header file you include? These functions should likely be declared as extern C
(or however you do that in Fortran), which would fix your capitalization issue.– Cris Luengo
Apr 3 at 16:46
Are you sure you should declare the MATLAB functions?
mwPointer mxGetDoubles
. Aren't those defined in the header file you include? These functions should likely be declared as extern C
(or however you do that in Fortran), which would fix your capitalization issue.– Cris Luengo
Apr 3 at 16:46
This is how MathWorks specifies the Fortran test file, so that was how I wrote my copy. mxGetDoubles is defined in the header file, but if I remove the declaration, I get
Error: Function ‘mxgetdoubles800’ at (1) has no IMPLICIT type
– zaen
Apr 3 at 16:51
This is how MathWorks specifies the Fortran test file, so that was how I wrote my copy. mxGetDoubles is defined in the header file, but if I remove the declaration, I get
Error: Function ‘mxgetdoubles800’ at (1) has no IMPLICIT type
– zaen
Apr 3 at 16:51
I see. Fortran is a weird language... :) -- Did you try compiling one of the demos that come with MATLAB?
mex([matlabroot '/extern/examples/refbook/timestwo.F'])
.– Cris Luengo
Apr 3 at 17:03
I see. Fortran is a weird language... :) -- Did you try compiling one of the demos that come with MATLAB?
mex([matlabroot '/extern/examples/refbook/timestwo.F'])
.– Cris Luengo
Apr 3 at 17:03
Yes, those fail as well. They succeed on Linux, and I think I've found the reason. The Linux libraries export symbols in a gfortran-compatible way, e.g. mxisnumeric800_. The underscore can be removed with -fno-underscoring, but the gfortran developers didn't include the -fsymbol-case-upper option from g77. That, I'm pretty sure, is the problem; gfortran forces symbols to be lowercase, while the Intel compiler goes for uppercase.
– zaen
Apr 3 at 17:10
Yes, those fail as well. They succeed on Linux, and I think I've found the reason. The Linux libraries export symbols in a gfortran-compatible way, e.g. mxisnumeric800_. The underscore can be removed with -fno-underscoring, but the gfortran developers didn't include the -fsymbol-case-upper option from g77. That, I'm pretty sure, is the problem; gfortran forces symbols to be lowercase, while the Intel compiler goes for uppercase.
– zaen
Apr 3 at 17:10
Ah, that must be it. MATLAB supports the Intel Fortran compiler only on Windows.
– Cris Luengo
Apr 3 at 17:15
Ah, that must be it. MATLAB supports the Intel Fortran compiler only on Windows.
– Cris Luengo
Apr 3 at 17:15
add a comment
|
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406709%2fmatlab-gives-undefined-reference-errors-trying-to-use-gfortran-on-windows%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406709%2fmatlab-gives-undefined-reference-errors-trying-to-use-gfortran-on-windows%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Are you sure you should declare the MATLAB functions?
mwPointer mxGetDoubles
. Aren't those defined in the header file you include? These functions should likely be declared asextern C
(or however you do that in Fortran), which would fix your capitalization issue.– Cris Luengo
Apr 3 at 16:46
This is how MathWorks specifies the Fortran test file, so that was how I wrote my copy. mxGetDoubles is defined in the header file, but if I remove the declaration, I get
Error: Function ‘mxgetdoubles800’ at (1) has no IMPLICIT type
– zaen
Apr 3 at 16:51
I see. Fortran is a weird language... :) -- Did you try compiling one of the demos that come with MATLAB?
mex([matlabroot '/extern/examples/refbook/timestwo.F'])
.– Cris Luengo
Apr 3 at 17:03
Yes, those fail as well. They succeed on Linux, and I think I've found the reason. The Linux libraries export symbols in a gfortran-compatible way, e.g. mxisnumeric800_. The underscore can be removed with -fno-underscoring, but the gfortran developers didn't include the -fsymbol-case-upper option from g77. That, I'm pretty sure, is the problem; gfortran forces symbols to be lowercase, while the Intel compiler goes for uppercase.
– zaen
Apr 3 at 17:10
Ah, that must be it. MATLAB supports the Intel Fortran compiler only on Windows.
– Cris Luengo
Apr 3 at 17:15