Incorrect number of arguments into mex file

2 Ansichten (letzte 30 Tage)
Etienne Coetzee
Etienne Coetzee am 6 Mai 2017
Kommentiert: Etienne Coetzee am 10 Mai 2017
Hi All
I have a mex file that has worked for the last 10 years (up to R2015b) and now is giving me problems since I have upgraded my Matlab version. The problem is that I check the number of input arguments and when it is not equal to two it throws an error. When I call the mex function it now sometimes throws an error, where it does not seem to pass any arguments in. When I run through the debugger, stop at the mex function call, and then call, it seems to work. I am definitely passing in the correct arguments. The problem seems to be spurious and does not always show up. It seems to be some or other initialisation problem or something like this.
Any help would be appreciated
Etienne
  3 Kommentare
Philip Borghesani
Philip Borghesani am 6 Mai 2017
I think were going to need a bit more information here. What platform(s) are you using? are both tested versions the same bit width? When you say it works when debugging do you mean the MATLAB debugger or a FORTRAN debugger?
If using the MATLAB debugger makes a difference we are going to need to see some MATLAB code from the call site and I suggest you add some test code in your MATLAB code to examine the arguments being passed from MATLAB when the debugger is not running.
Etienne Coetzee
Etienne Coetzee am 6 Mai 2017
Hi Philip
It is on a 64 bit machine and I mean the Matlab debugger. I will have to set up a test script and then post it. The only thing that has changed is the Matlab version. Everything else is the same. Same Fortran compiler etc.
Regards
Etienne

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

James Tursa
James Tursa am 8 Mai 2017
Particularly for Fortran, you should always use the exact signature that is in the doc. Sometimes that signature changes from release to release, or maybe the default compiler options for mexing have changed. Either one of these can trip you up. E.g., look at this from your code:
SUBROUTINE MEXFUNCTION(NLHS, PLHS, NRHS, PRHS)
!
!
!$ USE OMP_LIB
IMPLICIT NONE
MWPOINTER PLHS(*), PRHS(*), mxDuplicateArray
MWSIZE NLHS, NRHS
The signature from the doc is:
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
integer nlhs, nrhs
mwPointer plhs(*), prhs(*)
You've got NLHS and NRHS typed as MWSIZE, but the signature in the doc says the type should be integer. This could be a mismatch, since MWSIZE might be defined as an integer*8 but a default integer might be an integer*4. There is no automatic type promotion in Fortran like there is in C/C++, so this might cause a problem. It would be best to type NLHS and NRHS exactly like the doc states.
  2 Kommentare
Etienne Coetzee
Etienne Coetzee am 9 Mai 2017
Thanks James. I will give that a try.
Etienne Coetzee
Etienne Coetzee am 10 Mai 2017
James, it worked a treat. Thanks! Made my day!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Write C Functions Callable from MATLAB (MEX Files) finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by