Sorry for the multiple posts. Its not that it works only in Gnu debugger, but it turns out it works sometimes and sometimes not.
I can open matlab, mex the file, do a=timestwo(5) and it might work. Close matlab, open matlab, mex the file, do the same command as before, and seg fault.
The reason I thought it was gnu debugger which helped was just that I got lucky twice in gnu debugger.
"Ali Yurukoglu" <aliy@remove.nyu.edu> wrote in message <hhbif3$crc$1@fred.mathworks.com>...
> Just an update: timestwo works when I run it in gnu debugger, but seg faults when I run it in matlab.
>
> I modified timestwo and renamed it timestwo.F90
>
> #include "fintrf.h"
>
> subroutine mexFunction(nlhs, plhs, nrhs, prhs)
> mwpointer plhs(*), prhs(*)
> mwpointer mxGetPr, mxCreateDoubleMatrix
> mwpointer x, y
> integer nlhs, nrhs
> integer mxIsNumeric
> mwsize mxGetM, mxGetN
> mwsize m, n, size
>
> x = mxGetPr(prhs(1))
>
> m = mxGetM(prhs(1))
> n = mxGetN(prhs(1))
> size = m*n
>
> plhs(1) = mxCreateDoubleMatrix(m,n,0)
> y = mxGetPr(plhs(1))
>
> call timestwo(%val(y), %val(x),m,n)
>
>
> return
> end
>
> subroutine timestwo(y, x, m, n)
> implicit none
> mwsize m, n
> double precision x(m,n), y(m,n)
> integer i,j
>
> do i=1,m
> do j=1,n
> y(i,j) = 2.0 * x(i,j)
> end do
> end do
>
> end
>
>
>
>
> "Ali Yurukoglu" <aliy@remove.nyu.edu> wrote in message <hgtk75$7tf$1@fred.mathworks.com>...
> > Yes, well the seg fault happens with the (compiled mex file) of timestwo.F provided as a matlab example even. Here is the output from the compiler.
> >
> > Then I do a=timestwo(3) and I get a seg fault.
> >
> > mex timestwo.F v
> > > mexopts.sh sourced from directory (DIR = .)
> > FILE = /somepath/mexopts.sh
> > 
> > > MATLAB = /path/software/matlab2009b
> > > CC = gcc44
> > > CC flags:
> > CFLAGS = ansi D_GNU_SOURCE fexceptions fPIC fnoomitframepointer pthread
> > CDEBUGFLAGS = g
> > COPTIMFLAGS = O mtune=native DNDEBUG
> > CLIBS = Wl,rpathlink,/path/software/matlab2009b/bin/glnxa64 L/path/software/matlab2009b/bin/glnxa64 lmx lmex lmat lm lstdc++
> > arguments = DMX_COMPAT_32
> > > CXX = g++44
> > > CXX flags:
> > CXXFLAGS = ansi D_GNU_SOURCE fPIC fnoomitframepointer pthread
> > CXXDEBUGFLAGS = g
> > CXXOPTIMFLAGS = O mtune=native DNDEBUG
> > CXXLIBS = Wl,rpathlink,/path/software/matlab2009b/bin/glnxa64 L/path/software/matlab2009b/bin/glnxa64 lmx lmex lmat lm
> > arguments = DMX_COMPAT_32
> > > FC = gfortran44
> > > FC flags:
> > FFLAGS = fexceptions fPIC fnoomitframepointer
> > FDEBUGFLAGS = g
> > FOPTIMFLAGS = O mtune=native
> > FLIBS = Wl,rpathlink,/path/software/matlab2009b/bin/glnxa64 L/path/software/matlab2009b/bin/glnxa64 lmx lmex lmat lm
> > arguments = DMX_COMPAT_32
> > > LD = gfortran44
> > > Link flags:
> > LDFLAGS = pthread shared Wl,versionscript,/path/software/matlab2009b/extern/lib/glnxa64/fexport.map Wl,noundefined
> > LDDEBUGFLAGS = g
> > LDOPTIMFLAGS = O mtune=native
> > LDEXTENSION = .mexa64
> > arguments =
> > > LDCXX =
> > > Link flags:
> > LDCXXFLAGS =
> > LDCXXDEBUGFLAGS =
> > LDCXXOPTIMFLAGS =
> > LDCXXEXTENSION =
> > arguments =
> > 
> >
> >
> > Warning: You are using gcc version "4.4.0". The earliest gcc version supported
> > with mex is "4.1". The latest version tested for use with mex is "4.2".
> > To download a different version of gcc, visit http://gcc.gnu.org
> >
> > > gfortran44 c I/path/software/matlab2009b/extern/include I/path/software/matlab2009b/simulink/include fexceptions fPIC fnoomitframepointer DMX_COMPAT_32 O mtune=native "timestwo.F"
> >
> > > gfortran44 O mtune=native pthread shared Wl,versionscript,/path/software/matlab2009b/extern/lib/glnxa64/fexport.map Wl,noundefined o "timestwo.mexa64" timestwo.o Wl,rpathlink,/path/software/matlab2009b/bin/glnxa64 L/path/software/matlab2009b/bin/glnxa64 lmx lmex lmat lm
> >
> >
> > I don't understand every option in the sh file, so perhaps it is one of those. Before going one by one, I am hoping to find someone who can see easily what the problem is.
> >
> > thank you
> >
> >
> >
> > "James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <hgsk8o$mdi$1@fred.mathworks.com>...
> > > "Ali Yurukoglu" <aliy@remove.nyu.edu> wrote in message <hgrhip$eb5$1@fred.mathworks.com>...
> > > > I have some fortran mex files that work beautifully when compiled in 64 bit vista with ifort (version 11.1).
> > > >
> > > > The same mex files seg fault when compiled with gfortran 4.4 and run on linux. According to the gnu debugger, the seg fault is in the gateway routine at one of the mex commands.
> > > >
> > > > Has anyone had this problem? I know gfortran 4.4 is not supported officially (neither is ifort 11.1), but I am using the %val construct. As I understand, versions of gfortran which are officially supported by TMW don't understand %val.
> > > >
> > > > thank you for your help!
> > >
> > > Can you post a minimal code that duplicates the problem?
> > >
> > > James Tursa
