我喜欢在iMac上使用编辑器Visual Studio Code。我知道如何执行一个python脚本。我想用VScode也运行一个Fortran程序。我使用的是gfortran。我已经加载了现代Fortran的扩展名,语法高亮工作正常。我的文件的扩展名是.f90。
我的问题是我不知道如何编译和执行我的代码。有没有什么方法可以在Visual Studio Code中完成。
我在Windows上工作,但我解决了一个类似的问题,如下所示 CC++包的说明.
你需要创建一个目录 .vscode
在工作目录中,即您的 .f90
文件为常驻文件,并在该文件中创建以下两个文件 .vscode
目录。
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "gfortran gfortran.exe build active file",
"type": "shell",
"command": "C:\\TDM-GCC-64\\bin\\gfortran.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\a.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
] }
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Iniciar",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\TDM-GCC-64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Habilitar a reformatação automática para gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
] }
该文件 tasks.json
允许您生成您的 a.exe
文件,使用 终端 -> 运行构建任务.... 该文件 launch.json
允许您使用调试器[F5]在 a.exe
编译过程中产生的文件。
您必须注意在编译过程中产生的 PATH
变量。我的 gfortran.exe
编译器位于 C:\TDM-GCC-64\bin
目录。当你在 LinuxFreeBSDUnix 安装中使用时,你可能必须改变这个目录。