Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Solutions Academia Support User Community Company
spacer spacer spacer spacer spacer spacer

Technical Solutions

How can I debug a Fortran MEX file on Windows using Intel, Compaq, or Digial Visual Fortran compilers with Microsoft Visual Studio?


Date Last Modified: Friday, June 26, 2009
Solution ID:   1-32VRZ1
Product:   MATLAB
Reported in Release:   No Release
Platform:   Windows
Operating System:   Windows Any
 

Subject:

How can I debug a Fortran MEX file on Windows using Intel, Compaq, or Digial Visual Fortran compilers with Microsoft Visual Studio?

Problem Description:

I would like to debug a Fortran MEX file in Windows.

Solution:

This bug has been fixed in Release 2007b (R2007b). For previous product releases, read below for any possible workarounds:

This solution is specific to Compaq Visual Fortran, Intel Visual Fortran, or Digital Visual Fortran with the Microsoft visual development environment as the debugger. For other configurations, see the Debugging section of Tech Note 1605, MEX-files Guide:
http://www.mathworks.com/support/tech-notes/1600/1605.html

You can debug Fortran MEX-files on Windows which were compiled with Compaq Visual Fortran, Digital Visual Fortran, or the Intel Visual Fortran with the Microsoft visual development environment.

1. Select your Fortran compiler in MATLAB using the MEX command.
mex -setup
2. To debug a MEX-file from within MATLAB, you must first compile the MEX-file with the -g option. The -g option builds the MEX-file with debugging symbols included. The MATLAB current directory must be your source code directory.
mex -g yoursfun.f otherfile.f
This will create the mex-file.

[Note: The file extension of 32-bit Windows MEX-files has been changed from ".dll" to ".mexw32" in MATLAB 7.1 (R14SP3).
Hence if you are using MATLAB 7.1 (R14SP3) or a newer version, instead of the ".dll" extension, the compiled MEX files will have a .mexw32 extension (for 32-bit version of Windows), or a .mexw64 extension (for a 64-bit version of Windows)]

3. Exit your MATLAB session

4. Open up a DOS window (Start -> Programs -> Command Prompt), and change directories to the directory where your source code and the compiled MEX-file are located. Then type:


dfdev <mex-file name>
if you are using the Compaq or Digital Visual Fortran compiler, or

msdev <mex-file name>
if you are using Intel Fortran with Microsoft Visual Studio. Note that dfdev brings up the Compaq or Digital Visual Fortran debugger which also use the Microsoft visual development environment.

Here <mex-file name> is the name of the mex-file you want to debug, with the appropriate extension.

This will start up the compiler. This command will fail if dfdev.exe (or msdev.exe) is not on the system path. If you receive an error message when executing the dfdev command, you will need to add the compiler directories to your system path. You should refer to the compiler documentation for more information on defining the system path for your compiler.

5. In the compiler environment, select Settings from the Project menu. In the dialog box that opens, select the Debug tab. In the edit box labeled Executable for debug session, enter the full path to where the MATLAB executable resides. For example, you would enter $MATLABROOT\bin\win32\matlab.exe (where $MATLABROOT is the MATLAB root directory on your machine, as returned by typing:
matlabroot
at the MATLAB command prompt.)

In the edit box labeled Program Arguments, enter

-nojvm
The other edit boxes in this dialog box should remain empty.

6. Open the source files by selecting File -> Open. Set a breakpoint on the desired line of code by right clicking with your mouse on the line of code, and selecting Insert/Remove Breakpoint.

7. From the Build menu, select Debug, and click Go. A dialog box will appear that warns you that the MATLAB executable (matlab.exe) does not have debugging information. This is expected, as we do not ship a debug version of MATLAB. Click OK to close this dialog box.

8. A new MATLAB session will start. You should be in the directory where your MEX file is located. Execute your code which calls the MEX file, and you should be running the MEX file in the Microsoft visual development environment. For more information on how to use the debugging features, in the compiler environment, refer to the compiler documentation.

Please provide feedback to help us improve this Solution
Contact support
E-mail this page
Print this page