1
votes

This is Subhash. I am having problem in linking fortran-matlab mex files. I am running MATLAB R2010a. I am trying to mex fortran subroutines in MATLAB. I have installed MSYS, MinGW and gfortran. I have also downloaded and extracted gnumex in the c:\documents\MATLAB folder. I entered gnumex to run the installation settings. At this point, I see a window pop-up and I entered the following:

  1. MinGW's root directory ---> Pointed towards c:\mingw b) Cygwin's
  2. root directory -----> left blank c)
  3. Path to g95.exe ------> c:\mingw\bin
  4. path to gfortran.exe ------> c:\program files\gfortran\bin e)
  5. path to gnumex utilities ------> c:\users.....\matlab\gnumex
  6. environment linking type ------> MinGW
  7. generate mex dll or engine-----> mex
  8. language for compilation -------> fortran 77
  9. add stub ------> no
  10. optimization level -----> -O3

  11. path for libraries and .def files c:\users...\Roaming\MathWorks\MATLAB\R2010a\gnumex

  12. Mex options file to create: c\users...\Roaming\MathWorks\MATLAB\R2010a\mexopts.bat

The above is my installation setup for mex with gnumex. When I hit make options file, an warning message pops out which says " cannot corret mex.pl ..... "cannot open c:...\R2010a\bin\mex.pl for writing"

and when I hit ok, again it pops out saying to confirm overwrite of mexopts.bat . I hit confirm and the opt file is created.

At this point I should have my mex setup ready. But, when I run the fortran mex examples xtimesy.f, etc.. ( I use mex filename.f at the command prompt) and I get the following error

g77: getValidInputLinkLibraries: No such file or directory c:\prog~1\MATLAB\R2010A\BIN\MEX.PL: Error: Link of 'xtimesy.mexw32' failed. Error using ---> mex at 222 unable to complete successfully.

I tried this uninstalling several times, but ended up with the same error. Could anyone please let me know where am I going wrong. Is this not the correct procedure to link the g77? Please throw some light on this.

I appreciate your time..

Thanks.

1

1 Answers

1
votes

I recently tried to mex some fortran routines and failed due to the poor support for fortran compilers by matlab in windows. I got around the problem by using f2c to convert the fortran to C code, then creating a gateway routine in C which calls the automatically generated C code functions and mexing the resul using the visual studio 2008 compiler which integrates nicely with matlab (the free express edition version is sufficient, you will also be able to use it for debugging).

You can get f2c from http://www.netlib.org/f2c/. You must link the produced C code to the f2c library, which you may also have to build from the sources.

I know this all sounds very complicated, but it was easiest solution I found.