Windows下VSCode搭建Fortran环境
1. 下载VSCode
下载地址: https://code.visualstudio.com/Download
下载然后一路安装即可
2. 下载MinGW-W
下载之后解压记住路径.
例如我放在: C:\environment\mingw64
3. 搭建环境变量
-
打开环境变量
? 即在系统变量中加入:C:\environment\mingw64\bin
? 注意: 结合自己的路径.
-
测试是否成功
打开cmd, 输入gcc , 显示如下, 则配置成功
4. 编写Fortran代码
-
打开VSCode, 并新建文件
program projectName implicit none print *, "Hello world" !fortran语言注释 pause写上, 运行窗口不闪退 pause end program projectName
-
写代码环境才能运行
在当前项目下新建文件夹:
.vscode
在该文件夹下,新建文件:
launch.json
复制以下代码在该文件{ "version": "0.0.1", "configurations": [ { "name": "Fortran Launch (GDB)", "type": "cppdbg", "request": "launch", "targetArchitecture": "x86", "program": "${workspaceRoot}\\${fileBasenameNoExtension}.exe", "MIMode": "gdb", "miDebuggerPath": "C:/environment/mingw64/bin/gdb.exe",//结合自己的路径! "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}", "externalConsole": true, "preLaunchTask": "gfortran" }, { "name": "Intel Debug Attach", "type": "cppvsdbg", "request": "attach", "processId": "${command:pickProcess}" } ] }
注意: "miDebuggerPath": "C:/environment/mingw64/bin/gdb.exe" 这是我的mingw64路径
在该文件夹下,新建文件:
tasks.json
复制以下代码在该文件{ "version": "2.0.0", "command": "gfortran", "args": [ "-g", "${file}", "-o", "${workspaceRoot}\\${fileBasenameNoExtension}.exe" ], "presentation": { "echo": true, "reveal": "always", "focus": false, "panel": "new", //这里shared表示共享,改成new之后每个进程创建新的端口 "showReuseMessage": true, "clear": false } }
-
运行代码
成功!
以后新建新的Fortran项目, 将
.vscode
文件夹复制到别的项目下即可