首先要安装编译器,在Windows下安装MinGW-w64,然后在系统环境里添加编译器的路径。在Linux里直接安装gfortran 编译器即可,这个过程不再赘述。
然后需要安装python和vs code。
然后再配置vscode:
Fortran在vscode 里的设置
只要安装一个插件,就是Moden Fortran。其他三个可能组合在一起可以使用(fortran, FORTRAN IntelliSense,Fortran Breakpoint Support),但是与Modern Fortran是冲突的。
必须配合fortls作为后台debug server,用pip install fortls 安装就行。
可以配合fident 或者 fprettify 来格式化代码(pip install)
然后是launch和tasks配置文件:
Windows下的配置文件
tasks.json
{ "tasks": [ { "type": "shell", "label": "gfortran.exe fang", "command": "C:\\mingw-w64\\bin\\gfortran.exe", "args": [ "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "C:\\mingw-w64\\bin" } } ], "version": "2.0.0" } |
luanch.json
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: Debugging in Visual Studio Code "version": "0.2.0", "configurations": [ { "name": "gfortran.exe build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "C:\\mingw-w64\\bin\\gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "gfortran.exe fang" } ] } |
Linux下修改一下编译器和调试器的路径即可,比如//改成\,比如C:\\mingw-w64\\bin\\gdb.exe 改成 gdb