1

I am trying something that is not supported. I want to use the NAG Fortran compiler (release 5.3.1) to mex a Fortran file.

Using the command:

nagfor -ideclient -abi=64 -compatible -fpp -I"C:\Program Files\MATLAB\R2013b\extern\include" -Wl,-shared -thread_safe -L"C:\Program Files\MATLAB\R2013b\bin\win64" timesto.F -lmx -lmex -lmat -o timesto.mexw64

I am able to compile and link an adapted version of the timestwo.F Fortran example.

I used the very simple code below and this works well.

#include "fintrf.h"
  subroutine mexFunction(nlhs, plhs, nrhs, prhs)
C     Declarations
  implicit none
C     mexFunction arguments:
  mwPointer plhs(*), prhs(*)
  integer nlhs, nrhs
  call mexEvalString('why')
  end

Notice that mexEvalString is a function.

If I now change

  call mexEvalString('why')

into

  call mexErrMsgTxt('why')

The compilation still works. However, Matlab crashes without giving any indication why.

The only difference I see between both statements is that one contains a subroutine instead of a function.

What is going wrong and how do I fix this?

francescalus
  • 30,576
  • 16
  • 61
  • 96
Hugo
  • 159
  • 2
  • 11
  • 1
    An aside: since you have a licence for it stick with the NAG compiler. It produces very good diagnostics and the executables will be competitive in speed with any of its free alternatives. – High Performance Mark Mar 26 '14 at 11:10
  • As noted in the question, `mexEvalString` is a function, so shouldn't be `call`ed. – francescalus Mar 26 '14 at 11:27
  • Thanks for the comments. If I let mexEvalString return an integer value is also works. But that still leaves the problem with the subroutine crash. – Hugo Mar 26 '14 at 11:40
  • 1
    This probably doesn't really help you, but I have it seeming to work with nagfor under Linux (R2013a). That isn't too transferable, so I can only suggest fiddling with the compiler flags. – francescalus Mar 27 '14 at 18:18
  • Could you give me a list of the flags you use in both compile and link stages? Maybe I am missing a very obvious one. – Hugo Mar 28 '14 at 08:18
  • I used (with the long but obvious paths knocked out): `nagfor -c -I(..) -fpp -PIC -DMX_COMPAT_32 -O test.F ; nagfor -O -Wl,-shared -Wl,-Wl,,--version-script,(..)fexport.map -Wl,--no-undefined -unsharedrts -o test.mexa64 test.o -Wl,-Wl,,-rpath,(..) -L(..) -lmx -lmex -lmat -lm` – francescalus Mar 28 '14 at 10:12
  • Thanks for the command line options but incorporating -PIC --no-undefined and -unsharedrts I stilol only get a crash with the subroutine call and not with the funciton call. – Hugo Mar 28 '14 at 12:57

0 Answers0