Is there any approach to work on visual studio with gfortran? I have Windows 10, Visual Studio 2019 and gcc 7 installed using Cygwin.
-
Can you please provide an elaborate instructions as I am new to this?– sriMay 10, 2019 at 18:01
1 Answer
Let assume Cygwin installation path is D:\Cygwin
and gcc-fortran
package is already installed in Cygwin.
- Add the Cygwin installation folder in
%PATH%
environment variable in Control Panel. - Create
HelloWorld.f90
file in a folder:
program hello
print *,"Hello World!"
end program hello
- Open that folder in VSCode.
- Go to Terminal > Configure Tasks > Create task.json file from template > Others.
- VSCode will automatically create and open a
tasks.json
file in.vscode
folder. - Add this JSON code:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "D:\\Cygwin\\bin\\gfortran.exe",
"args": [
"HelloWorld.f90"
],
"group": "build",
"presentation": {
"reveal": "always"
}
}
]
}
- Add other required parameters in
args
field in the above JSON file. - Go to Terminal > Run Build Task or press Ctrl+Shift+B to build it. Click on build.
The gfortran path will be different if different package is installed. Optionally, fortran extensions can be downloaded from Visual Studio MarketPlace for syntax highlighting. For further information, read tasks in VSCode
-
Disclaimer: I am not a fortran expert. So, my procedure may not be perfect. May 11, 2019 at 6:08