Ian
Ian

Reputation: 53

Trying to add a Fortran compiler for Matlab

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

Upvotes: 0

Views: 1343

Answers (2)

Adrian
Adrian

Reputation: 3306

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.

Upvotes: 1

Andreas H.
Andreas H.

Reputation: 6105

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.

Upvotes: 0

Related Questions