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

4 ビュー (過去 30 日間)

採用された回答

MathWorks Support Team
MathWorks Support Team 2021 年 2 月 16 日
編集済み: MathWorks Support Team 2021 年 2 月 16 日
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 MEX-files Documentation:
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. If dfdev.exe (or msdev.exe) cannot be located, as mentioned on Step 4, you can try to attach the MATLAB process to Visual Studio as described below:
In order to access the "Attach to Process" option in MSVC 2010 Express, you need to do the following:
- - click on Tools >> Settings >> and select “Expert Settings”
Now if you click on Tools, you will be able to find the Attach to Process option. Now attach the "MATLAB.exe" corresponding to the exact MATLAB version you are running. You will now be able to debug your file.
6. 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.
7. 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.
8. 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.
9. 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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWrite C Functions Callable from MATLAB (MEX Files) についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by