For Programmers: Free Programming Magazines  


Home > Archive > Matlab > August 2005 > Compiling Fortran to mex on Linux









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Compiling Fortran to mex on Linux
Claus Hetzer

2005-08-12, 5:05 pm

Aloha all-

I have a Fortran program (not written by me) that I need to compile
to a mex file on my Linux box. I am running SuSE 9.3, with Matlab 7.
The problem is that the mex command wants to use the g77 compiler,
which apparently has been folded into the gcc compiler by now; in any
case, I don't have g77, f77, etc. I have tried gcc and the Intel
Fortran compiler, ifort, and have been unable to get a library that
works; either it will crash MATLAB completely when I try to call its
functions, or it will complain of unresolved symbols, suggesting a
linking problem. Has anyone successfully compiled Fortran to mex
using either of these compilers, and if so which flags and options do
you use (I believe my problem lies therein). I am not an experienced
UNIX command-line compiler (i.e. I don't speak make) so if any
responses could be on a very basic level I would greatly appreciate
it.

Many thanks in advance
Claus Hetzer
Christopher Hulbert

2005-08-12, 5:05 pm

Claus Hetzer wrote:
> Aloha all-
>
> I have a Fortran program (not written by me) that I need to compile
> to a mex file on my Linux box. I am running SuSE 9.3, with Matlab 7.
> The problem is that the mex command wants to use the g77 compiler,
> which apparently has been folded into the gcc compiler by now; in any
> case, I don't have g77, f77, etc. I have tried gcc and the Intel
> Fortran compiler, ifort, and have been unable to get a library that
> works; either it will crash MATLAB completely when I try to call its
> functions, or it will complain of unresolved symbols, suggesting a
> linking problem. Has anyone successfully compiled Fortran to mex
> using either of these compilers, and if so which flags and options do
> you use (I believe my problem lies therein). I am not an experienced
> UNIX command-line compiler (i.e. I don't speak make) so if any
> responses could be on a very basic level I would greatly appreciate
> it.
>
> Many thanks in advance
> Claus Hetzer


I've used gfortran, g95, and ifort 9.0 on fedora core 3 and 4. Maybe if
you gave more information on your problem. What symbols are missing.
Is there a crash dump report?
barrowes@alum.mit.edu

2005-08-31, 7:01 pm

For g95, this works for me:
FC='g95'
FFLAGS='-fPIC -r8'
FLIBS="$RPATH $MLIBS"
FOPTIMFLAGS='-O3'
# FDEBUGFLAGS='-g'
LD="$COMPILER"
LD="$FC"
LDEXTENSION='.mexglx'
LDFLAGS="-pthread -shared
-Wl,--version-script,$TMW_ROOT/extern/lib/$Arch/$MAPFILE"
LDOPTIMFLAGS=$FOPTIMFLAGS
LDDEBUGFLAGS='-g'
POSTLINK_CMDS=':'

and for ifort:
FC='ifort'
FFLAGS='-fPIC -r8'
FLIBS="$RPATH $MLIBS -lm -llapack -lslatec -lf2c"
FOPTIMFLAGS='-O3'
LD="$COMPILER"
LD="gcc"
LD="ifort"
LDEXTENSION='.mexglx'
LDFLAGS="-shared
-Wl,--version-script,$TMW_ROOT/extern/lib/$Arch/$MAPFILE"
LDOPTIMFLAGS=$FOPTIMFLAGS
LDDEBUGFLAGS='-g'
POSTLINK_CMDS=':'

For examples of fortran mex files that use pointers instead of %val,
see the examples included with matlab2fmex:
http://www.mathworks.com/matlabcent...objectType=FILE

f2matlab may also interest you:
http://www.mathworks.com/matlabcent...objectType=FILE

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com