Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to debug a fortran mex program?

Subject: How to debug a fortran mex program?

From: David Webb

Date: 3 Mar, 2009 12:37:01

Message: 1 of 4

My system is Windows XP, and my fortran compiler is Compaq Visual Fortran 6.6, I have chosen it by "mex -setup". Then I can compile my fortran mex program with command "mex -g *.f90" and run the mex function, but the result is not right. So I want to debug.
I use the method introduced in following link to debug my program:
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab.html
External Interfaces/Creating Fortran MEX-Files/Debugging Fortran Source MEX-Files

At first, I open my Compaq Visual Fortran Developer Studio, and choose "Build---Start Debug--Attach to Process...---Matlab". Then I open my fortran mex file in the Developer Studio, but can't insert Breakpoint in it. When I run the mex function in Matlab, I can't get into the mex file to debug. So what should I do?

Subject: How to debug a fortran mex program?

From: Rune Allnor

Date: 3 Mar, 2009 13:32:18

Message: 2 of 4

On 3 Mar, 13:37, "David Webb" <weihy1...@163.com> wrote:
> My system is Windows XP, and my fortran compiler is Compaq Visual =A0Fort=
ran 6.6, =A0I have chosen =A0it by "mex -setup". =A0Then =A0I =A0can compil=
e my fortran mex program with command "mex -g =A0*.f90" and run the mex fun=
ction, =A0but the result is not right. So I want to debug. =A0
> I use the method introduced in following link to debug my program:http://=
www.mathworks.com/access/helpdesk/help/techdoc/matlab.html
> External Interfaces/Creating Fortran MEX-Files/Debugging Fortran Source M=
EX-Files
>
> At first, =A0I open my Compaq Visual Fortran Developer Studio, and choose=
 "Build---Start Debug--Attach to Process...---Matlab". Then I open =A0my fo=
rtran mex file in the Developer Studio, =A0but =A0can't insert Breakpoint i=
n it. When I run the mex function in Matlab, =A0I can't get into the mex fi=
le to debug. So what should I do?

Did you MEX the program with the correct optons to
produce debug code?

Apart from that, I always develop MEX business code
in standard C++, testing and debugging under the
C++ IDE. I only use MEX for the interface routine.
This way I get the benefits from the familiar test
and debug tools in the C++ IDE, and I keep the matlab
MEX issues to a bare minimum. If there is a problem
with the MEX routine, it is confined to the interfacing,
which narrows down the possible errors.

Rune

Subject: How to debug a fortran mex program?

From: David Webb

Date: 4 Mar, 2009 11:40:20

Message: 3 of 4


> Did you MEX the program with the correct optons to
> produce debug code?
>
> Apart from that, I always develop MEX business code
> in standard C++, testing and debugging under the
> C++ IDE. I only use MEX for the interface routine.
> This way I get the benefits from the familiar test
> and debug tools in the C++ IDE, and I keep the matlab
> MEX issues to a bare minimum. If there is a problem
> with the MEX routine, it is confined to the interfacing,
> which narrows down the possible errors.
>
> Rune

Thanks for your repply, Rune, I think I have mexed my program wiith the correct options . I use " -g" option when mex the code. And my program can work well now, but I still don't know how to debug the fortran mex program.

David

Subject: How to debug a fortran mex program?

From: Roland Neumann

Date: 8 Mar, 2009 17:50:17

Message: 4 of 4

In my case, it worked when I first started matlab and mexed the Fortran File with the -g option. I then opened Visual Studio (with previously Intel Fortran compiler) and attached to Matlab process. I could open the Mexfile afterwards and put breakpoints in it. They were never indicated correctly though. At mexw32 start, it then jumped to the breakpoints anyway. Besides, this never worked perfectly (some variables were not read out correctly). It was nearly perfect when logged in as administrator. You might try this.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us