Compiling hello.f90 with Visual Studio Code for WSL

I have:
Distributor ID: Ubuntu
Description: Ubuntu 22.04.1 LTS
Release: 22.04
Codename: jammy

with code:
~/prusso/fortranhello/hello.f90:
program hello
print *, “Hello World!”
end program

I have installed VS Code on the windows side for WSL as well as the Modern Fortran Extension for WSL as well as fortls which I installed via:

pip install fortls

which installed and VS Code notified me that fortls was installed and initialized. So far when I click the run button or the build task menu item in VS Code nothing happens. There is in the lower right hand corner an icon stating that Fortran is the current language. I did read the documentation about the launch.json however so far try as I might I was not able to get VS Code to compile and debug anything yet. Can someone please let me know what has to be done from this point to get hello.f90 to compile and debug with the Modern Fortran extension for WSL?

Thanks…

So I did put in a launch.json which now does execute and I have the print statement coming out after installing the WSL gdb extension however the debugger does not stop at any breakpoints it just continues past them and the program returns with exit code 0. Why are the breakpoints not working?

Hi @prusso75 welcome to the Fortran-lang Discourse

You didn’t specify the Modern Fortran version but I will assume you are using the pre-Release since compile and debug buttons are currently only available there. Pressing the Debug button should work AFAIK. Could you post the output of your Modern Fortran Output channel, after you have set the logging level to Debug in your settings


You need to add in your launch.json arguments to compile with debug symbols -g

Much gratitude you have pointed that out to me. So beyond adding in place of [“-g”] for arguments inside launch.json also I was able to find Logging settings for a C_Cpp system belonging to VS Codes settings dialog for some reason it wasn’t under Fortran settings on my particular machine that I also set to “Debug”.
So I tried to post the terminal out but I got a dialog that says new users can not post more than two links.

Thank you