How to debug a Windows* Fortran application from the command line


For Fortran applications built within Microsoft Visual Studio*, you can debug the program by setting a breakpoint at the first executable line and then pressing F5 (or clicking the GO button).  But if you built the application using command line tools, this method is not available.  This article describes how to begin debugging an application built from the command line.

Note: This technique requires that a supported version of Microsoft Visual Studio is installed. It will not work if you are using Microsoft Visual C++ Express Edition* or the Windows Platform SDK to support the compiler environment.

Building the Application

Add the /debug option to the ifort command when compiling and linking.  For example:

ifort /debug /Od hello.f90


ifort /c /debug /Od main.f90
ifort /c /debug /Od sub.f90
ifort /debug /exe:main.exe main.obj sub.obj

This will create a .pdb (Program Database) file alongside the executable.  The .pdb file is required for debugging. The /Od option disables optimization to enhance debugging.

Start Debugging

In order to start the debugger, you must be in a command prompt environment which includes definitions for Microsoft Visual Studio.  This is the default for an Intel Fortran "Build Environment" session.

Type the command:

devenv /debugexe hello.exe

where hello.exe is replaced with the name of your executable. If the program requires command line arguments, they may follow the executable name on the command line.

Wait for Visual Studio to finish loading.

You must now set a breakpoint at the main program.  To do this, select Debug > New Breakpoint > Break at Function... or press CTRL-B.  You will see a dialog similar to the following:


If you have built an IA-32 architecture application, type into the Function box the name:


Note that there is one underscore before MAIN and two underscores after.

If you have built an Intel® 64 architecture application, type into the Function box the name:


In this case there is no leading underscore and two trailing underscores.

Click OK.

Press F5 or click the Start Debugging button.  The program will now begin executing but will break at the Fortran main program.  From there you may set additional breakpoints as desired.

If at the end of the session you close Visual Studio and allow it to save the new Visual Studio solution it created, you can debug again just by opening the solution (.sln file).  Your previously set breakpoints will be preserved.


If you have comments or questions specifically relating to this article, use the Comments box below. For other questions, please visit our user forum.

Для получения подробной информации о возможностях оптимизации компилятора обратитесь к нашему Уведомлению об оптимизации.