There are two steps you need to configure:

  • Install MINGW-W64
  • Add the necessary extensions of Visual Studio Code

Install MINGW-W64

An installation package should be download in its homepage (http://mingw-w64.org).

Double click the executable file "mingw-w64-install.exe" and start to install.

When you meet the page "Settings", you should choose "x86_64" in Architecture options, change the Threads from "posix" to "win32" (if your operating system is linux or MacOs, you should choose "posix"), and in the "Exception" options you can select "seh".

After the installation of MINGW-W64 is complete, there is a indispensable step to ensure your software can be running normally.The path of installation directory should be found in your hard drive, such as "C:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin".And you should add it in your computer's system global variable "Path".

Some normal output information "gcc version 8.1.0 (x86_64-win32-seh-rev0, Built by MinGW-W64 project)" can be found when you type a string "gcc -v" in command prompt. If you have finished it, congratulation, MINGW-W64 have ben installed correctly.

Add the necessary extensions of Visual Studio Code

This step is easy for everyone, you just need to search extention packages in Visual Studio Code to install and all will be ok.

These packages:

  • Gimly81.fortran
  • ms-vscode.cpptools
  • ekibun.fortranbreaker

When you want to programme a fortran program, you also need to configure fortran evironment to ensure code can be compiled.

Create a new folder ".vscode" and write these two files in "Explorer" of Visual Studio Code:

launch.json

{
    "version": "0.0.1",
    "configurations": [
        {
            "name": "Fortran Launch (GDB)",
            "type": "cppdbg",
            "request": "launch",
            "targetArchitecture": "x86",
            "program": "${workspaceRoot}\\${fileBasenameNoExtension}.exe",
            "miDebuggerPath": "gdb.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "externalConsole": true,
            "preLaunchTask": "gfortran"
        }
    ]
}

tasks.json

{
    "version": "0.0.1",
    "command": "gfortran",
    "args": [
        "-g",
        "${file}",
        "-o",
        "${workspaceRoot}\\${fileBasenameNoExtension}.exe"
    ]
}

Then you can write code in your .f90 file. And compile it in "Start Debugging" from the menu of "Debug".

If the Fortran program interface flashback, you can add "pause" or "read(,)" before the tag "END PROGRAM" to solve it.

Last modified: 2020年3月30日

Comments

Write a Reply or Comment

Your email address will not be published.