Free Fortran Compiler - Win 64bit

7 views (last 30 days)
Alexander
Alexander on 12 Nov 2012
Commented: Rylan on 9 Nov 2019
Hi,
i need a Matlab-compatible free Fortran Compiler to compile mex files under win 64bit environment. Actually i work with a gfortran Version on my Mac wich has official Support. Is it possible to do so under win ? Or are there some known issues ?
Kind regards
Alex
p.s. I use the latest Matlab release R2012b

Accepted Answer

Ken Atwell
Ken Atwell on 16 Nov 2012
Sorry, the only supported compiler on win64 is the (not free) Intel Fortran compiler: <http://www.mathworks.com/support/compilers/R2012b/win64.html>

More Answers (1)

Ricolindo Carino
Ricolindo Carino on 9 Aug 2016
MATLAB R2015b on Windows 7 (64 bit) comes with TDM-GCC-64, gcc 4.9.2, but not gfortran. However, TDM-GCC-64 gfortran (gcc 5.1.0) can be separately installed and used to generate mexfiles from Fortran sources. Here's how I did it:
/*
* DMGmex.c - mexfunction for the Fortran subroutine DMG_BCJ.F,
* to evaluate the damage-plasticity model implemented in
* Fortran subroutine umat_dmg_55p_v1p1.f
* Version 2016-08-09, by RL Carino, carino@cavs.msstate.edu
*
* DMG_BCJ.F looks like:
*
* subroutine dmg_bcj(xin_props, rval, i_count)
* dimension xin_props(100) ! props() + settings
* dimension rval(3,1000) ! 1=stress, 2=strain, 3=state variable
* integer i_count ! actual number of columns in r_val
*
* The following compilation steps work on the setup:
*
* + Windows 7 (64-bits)
* + MATLAB R2015b, with TDM-GCC-64, gcc version 4.9.2 (tdm64-1) included
* in C:\MATLAB\SupportPackages\R2015b\MW_MinGW_4_9\bin
* + TDM-GCC-64, gfortran 5.1.0 installed separately in C:\TDM-GCC-64\bin
* + The PATH environment variable includes C:\TDM-GCC-64\bin
*
* Compile DMGmex.c as:
* >> mex -v -c -f C:\MATLAB\R2015b\bin\win64\mexopts\mingw64.xml DMGmex.c
*
* Compile DMG_BCJ.F and umat_dmg_55p_v1p1.f as:
* >> !gfortran -c DMG_BCJ.F -fno-underscoring
* >> !gfortran -c umat_dmg_55p_v1p1.f -fno-underscoring
*
* Link the object files as:
* >> !g++ -m64 -Wl,--no-undefined -shared -s -Wl,"C:\MATLAB\R2015b/extern/lib/win64/mingw64/mexFunction.def" DMGmex.obj DMG_BCJ.o umat_dmg_55p_v1p1.o C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\5.1.0\libgfortran.a C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\5.1.0\libquadmath.a -L"C:\MATLAB\R2015b\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -o DMGmex.mexw64
*
* Invoke DMGmex from MATLAB as:
* [rval, i_count] = DMGmex(xin_props);
*/
#include "mex.h"
void dmg_bcj(double *, double *, mwSize *);
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
mwSize m, n, size;
mwSize code;
double x[100], y[3000], c;
double *x_pr, *y_pr, *c_pr;
int i;
/* get RHS array */
m = mxGetM(prhs[0]);
n = mxGetN(prhs[0]);
size = m*n;
x_pr = mxGetPr(prhs[0]);
/* create LHS arrays */
plhs[0] = mxCreateDoubleMatrix(3, 1000, mxREAL);
plhs[1] = mxCreateDoubleMatrix(1, 1, mxREAL);
y_pr = mxGetPr(plhs[0]);
c_pr = mxGetPr(plhs[1]);
/* copy RHS to subroutine argument xin_props */
for ( i = 0; i < size; i++ ) {
x[i] = x_pr[i];
/* mexPrintf("\nprops(%d)= %g", i, x[i]); */
}
/* invoke the subroutine */
dmg_bcj(x, y, &code);
/* copy results to LHS */
for ( i = 0; i < 3000; i++ ) {
y_pr[i] = y[i];
}
c_pr[0] = 1.0E0*code;
return;
}
Hope this helps.
Ric Carino
  1 Comment
Rylan
Rylan on 9 Nov 2019
Can this mex be debugged with Visual Studio?

Sign in to comment.

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!