0
votes

I have a file with the extension .F, which I want to compile to use with my Matlab code. To do that I`m trying to use mex tool. "mex -setup FORTRAN -v" returns.

mex -setup FORTRAN -v

Verbose mode is on.

... Looking for compiler 'Intel Visual Fortran Composer XE 2011 with Microsoft SDK 7.1' ...

... Looking for environment variable 'IFORT_COMPILER12' ...No.

Did not find installed compiler 'Intel Visual Fortran Composer XE 2011 with Microsoft SDK 7.1'.

... Looking for compiler 'Intel Visual Fortran Composer XE 2011 with Microsoft Visual Studio 2008' ...

... Looking for environment variable 'IFORT_COMPILER12' ...No.

Did not find installed compiler 'Intel Visual Fortran Composer XE 2011 with Microsoft Visual Studio 2008'.

... Looking for compiler 'Intel Visual Fortran Composer XE 2011 with Microsoft Visual Studio 2010' ...

... Looking for environment variable 'IFORT_COMPILER12' ...No.

Did not find installed compiler 'Intel Visual Fortran Composer XE 2011 with Microsoft Visual Studio 2010'.

... Looking for compiler 'Intel Visual Fortran Composer XE 2013 with Microsoft Visual Studio 2008' ...

... Looking for environment variable 'IFORT_COMPILER14' ...No.

... Looking for environment variable 'IFORT_COMPILER13' ...No.

Did not find installed compiler 'Intel Visual Fortran Composer XE 2013 with Microsoft Visual Studio 2008'.

... Looking for compiler 'Intel Visual Fortran Composer XE 2013 with Microsoft Visual Studio 2010' ...

... Looking for environment variable 'IFORT_COMPILER14' ...No.

... Looking for environment variable 'IFORT_COMPILER13' ...No.

Did not find installed compiler 'Intel Visual Fortran Composer XE 2013 with Microsoft Visual Studio 2010'.

... Looking for compiler 'Intel Visual Fortran Composer XE 2013 with Microsoft Visual Studio 2012' ...

... Looking for environment variable 'IFORT_COMPILER14' ...No.

... Looking for environment variable 'IFORT_COMPILER13' ...No.

Did not find installed compiler 'Intel Visual Fortran Composer XE 2013 with Microsoft Visual Studio 2012'.

Error using mex

No supported compiler or SDK was found. For options, visit http://www.mathworks.com/support/compilers/R2014b/win64.html.

It seems to me that the problem is I don't have any default compiler. So I downloaded MGW with gfortran compiler and now I want to set it up as a tool for mex to compile. Surfing through internet I haven't found any instructions how to do so. I would be glad to advice how to do that or for any alternative way.

Some extra info for people who can think of alternatives. I got file with the extension .F and I have compiled binary with extension mexa64, which stands for Linux binary. But what I need to get is mexw64, which is the version for 64-bit Windows.

Additionally this is the output of getCompilerConfigurations, which shows that there is a C compiler and no Fortran compiler

mex.getCompilerConfigurations('C')

ans =

CompilerConfiguration with properties:

         Name: 'Microsoft Visual C++ 2012 (C)'
 Manufacturer: 'Microsoft'
     Language: 'C'
      Version: '11.0'
     Location: 'D:\apps\visualstudio2012'
    ShortName: 'MSVC110'
     Priority: 'A'
      Details: [1x1 mex.CompilerConfigurationDetails]
   LinkerName: 'link'
LinkerVersion: ''
       MexOpt: 'C:\Users\Ian\AppData\Roaming\MathWorks\MATLAB\R2014b\mex_C_win64.xml'

mex.getCompilerConfigurations('Fortran')

ans =

0x1 CompilerConfiguration array with properties:

Name
Manufacturer
Language
Version
Location
ShortName
Priority
Details
LinkerName
LinkerVersion
MexOpt
2
MATLAB has a specific list of which compilers are supported. Do you have any on their list?Ander Biguri
I do have some of the C++ compilers, but none of Fortran. I've googled some compilers from the Fortran list and it seems like the price for them is around 6-7 hundred dollars, which I'm not ready to spend for experimentIan
Please, stop adding ` , learn how to format.Ander Biguri
Unfortunately, MATLAB only supports a series of compilers. I highly doubt you will make any other compiler work. I mean, look at the verbose output, it just search a compiler in a list, and if its not there, error.Ander Biguri
Seems like it's true. I ended up installing Intel Visual Fortran Composer on my mac. There is a free version of it in case you have ".edu" email. Just in case anyone will need itIan

2 Answers

1
votes

You need to create your own mexopts setup xml file for the mingw fortran compiler.

In the /bin/mexopts folder there will be a mingw64.xml file. This is the mexopts file for the supported mingw gcc compiler. In the config options at the top it says Language="C".

The structure of the file is fairly clear in defining the commands for the compiler and linker etc. So you need to create an equivalent file for the FORTRAN compiling and linking and you can then set Language="FORTRAN".

Once you have created your mexopt file for example my_mingw_Fortran.xml you can then tell MATLAB mex to use this for FORTRAN by using the following command at the MATLAB prompt

mex setup:my_mingw_Fortran.xml FORTRAN -v

Sorry I don't have an example for mingw/gcc on Windows but I used this process to get MATLAB to use the Intel Fortran complier on a Linux machine.

0
votes

You could try the Gnumex tool. It replaces the default mex file infrastructure with the Mingw compiler (Actually you can switch back and forth between gnumex and builtin mex handling). For me (MATLAB 2014b) it works very well and I used it to compile Fortran code as well. I just needed to explicitly link with the gfortran librbary. It needs the TDM-GCC variant of mingw.