首页 > 解决方案 > 无法使用 task.json 在 macOS Catalina 的 vscode 中编译 fortran 90 代码

问题描述

我正在尝试在 macOS Catalina 的 vscode 中使用 gfortran 编译器编译 fortran 90 代码。当我gfortran -o ./main Hello.f90在 vscode 终端中使用命令时,它可以工作。但是,如果我尝试添加 task.json 并尝试“运行任务”,则会引发错误。gfortran: fatal error: cannot execute 'f951': execvp: No such file or directory compilation terminated.我已经尝试了几件事,包括find/usr/local/ -name f951此链接中的一件gfortran: error trying to exec 'f951': execvp: No such file or directory,但没有运气。请帮忙。

我的任务.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "gfortran",
            "args": [
                "-o",
                "./main",
                "Hello.f90"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]

}

标签: visual-studio-codefortrangfortran

解决方案


这是我的 task.json 看看它是否对你有帮助。注意注释行“.exe”。也许您可以在那里粘贴 macOS 的相关扩展。

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format    
"version": "2.0.0",
"_runner": "terminal",
"tasks": [
    {
        "label": "build_gfortran",
        "type": "shell",
        "windows": {
            "command": "gfortran"
        },
        "linux": {
            "command": "gfortran"
        },
        "osx": {
            "command": "gfortran"
        },
        "args": [
            "${file}",
            "-g",
            "-o",
        // "${workspaceRoot}\\${fileBasenameNoExtension}.exe"
            "${fileBasenameNoExtension}"
        ],
        "problemMatcher": [],
        "group": {
            "kind": "build",
            "isDefault": true
        }
     }
  ]
}

顺便说一句,第一次在这里发帖。干杯。


推荐阅读