I believe gnumex is completely outdated by now. I have been using mex out of the box with Matlab recently on my Mac with no problems, connecting with C and then calling Fortran from C. I would use gfortran with the switch -std=legacy. I would also use a C gateway function to connect between Matlab and Fortran. I don’t know much about what would happen on a Windows machine, but note that Matlab now claims to support MinGW 6.3 C/C++.
Here is a simple example:
#include"mex.h"// xy = prod_gw(x,y) calls prod.f do compute the scalar product dot(x,y)// Returns silently with xy = 0 if not called with 2 arguments or if x and y // have different lengths. Other errors are not caught.voidprod_(doublex[],doubley[],double*xy,int*n);voidmexFunction(intnlhs,mxArray*plhs[],intnrhs,constmxArray*prhs[]){double*xy,*x,*y;intn;plhs[0]=mxCreateDoubleMatrix(1,1,mxREAL);xy=mxGetPr(plhs[0]);*xy=0;if(nrhs!=2)return;n=mxGetNumberOfElements(prhs[0]);if(n!=mxGetNumberOfElements(prhs[0]))return;x=mxGetPr(prhs[0]);y=mxGetPr(prhs[1]);*xy=30;prod_(x,y,xy,&n);}
Hi,
I followed the steps to install gnumex by following the instructions on the page
http://gnumex.sourceforge.net/
When i tried to execute the command >>mex -v i got following error.
>> mex -v
This is mex, Copyright 1984-2007 The MathWorks, Inc.
-> Default options filename found in C:\Dokumente und Einstellungen\R74\Anwendungsdaten\MathWorks\MATLAB\R2009b
-------------------------------------------
-> Options file = C:\Dokumente und Einstellungen\R74\Anwendungsdaten\MathWorks\MATLAB\R2009b\mexopts.bat
MATLAB = C:\PROGRA~1\MATLAB\R2009b
-> COMPILER = gcc
-> Compiler flags:
COMPFLAGS = -c -DMATLAB_MEX_FILE
OPTIMFLAGS = -O3
DEBUGFLAGS = -g
arguments =
Name switch = -o
-> Pre-linking commands =
-> LINKER = C:\PROGRA~1\MATLAB\R2009b\sys\perl\win32\bin\perl.exe c:\gnumex\linkmex.pl
-> Link directives:
LINKFLAGS = -LC:\DOKUME~1\R74\ANWEND~1\MATHWO~1\MATLAB\R2009b\gnumex
LINKDEBUGFLAGS = -g -Wl,-image-base,0x28000000\n
LINKFLAGSPOST =
Name directive = -o .mexw32
File link directive =
Lib. link directive =
Rsp file indicator =
-> Resource Compiler = C:\PROGRA~1\MATLAB\R2009b\sys\perl\win32\bin\perl.exe c:\gnumex\rccompile.pl -o mexversion.res
-> Resource Linker =
-------------------------------------------
Usage:
MEX sourcefile1
or (to build an Ada S-function):
MEX -ada <sfcn>.ads
Use the -help option for more information, or consult the MATLAB API Guide.
C:\PROGRA~1\MATLAB\R2009B\BIN\MEX.PL: Error: No file names given.
??? Error using ==> mex at 221
Unable to complete successfully.
I do not know how to resolve this issue. So if any of you has idea, please let me know.
Saif
Did you find any solution to this?
I have the same problem.
I believe gnumex is completely outdated by now. I have been using mex out of the box with Matlab recently on my Mac with no problems, connecting with C and then calling Fortran from C. I would use gfortran with the switch -std=legacy. I would also use a C gateway function to connect between Matlab and Fortran. I don’t know much about what would happen on a Windows machine, but note that Matlab now claims to support MinGW 6.3 C/C++.
Here is a simple example:
I could then have a compile-link script:
and compile and run with:
With the newest Matlab you could also use mxGetDoubles instead of mxGetPr and mex with
mex -R2018a prod_gw.c prod.o
(with no complex numbers you get the same results)