visual-studio-code - 如何在VSCODE中设置tasks.json文件来编译Fortran程序?

标签 visual-studio-code fortran

我想设置 VScode(操作系统:Windows 10)来创建然后编译用 Fortran 90/95 编写的程序。我可以通过在终端中输入来做到这一点:gfortran -o Example_exe Example.f90然后 ./Example_exe .我不想每次都写这些行,所以我试着设置我的tasks.json文件以使用 gfortran 自动化构建例程作为编译器。
我找到了这个教程:https://titanwolf.org/Network/Articles/Article?AID=360e0bde-0507-4de4-960c-2eae8fa8c782#gsc.tab=0tasks.json给出的文件不清楚。
我可以要一个 tasks.json文件设置来自动化我的构建例程吗?
我安装了以下扩展:Modern Fortran、Fortran IntelliSense、Code Runner、Fortran Breakpoint Support

最佳答案

是的你可以。假设你想在 Debug模式下执行,你应该创建一个 tasks.json和一个 launcher.json并将它们放入 .vscode/在工作区的根目录。
假设以下文件结构和使用 GDB 的 Debug模式执行:
根/

  • .vscode/
  • 代码/
  • Example_exe


  • 这就是你的 tasks.json 应该是这样的:
    {
        "version": "2.0.0",
        "tasks": [
    
            {
                "label": "compile",
                "type": "shell",
                "command": "gfortran -o Example_exe Example.f90 -g",
                "options": {
                    "cwd": "code/"
                }
            }
        ]
    
    }
    
    然后,launch.json ,这将识别 tasks.json作为“预启动任务”。
    {
        "version": "0.2.0",
        "configurations":[
            {
                "name": "Run my example",
                "type": "cppdbg",
                "request": "launch",
                "program": "${workspaceFolder}\\code\\example_exe.exe",
                "args": ["],
                "stopAtEntry": false,
                "cwd": "${workspaceFolder}\\code",
                "miDebuggerPath": "gdb.exe",
                "preLaunchTask": "compile",
    
            }
        ]
    }
    
    按 F5(或在运行菜单中)启动调试器。
    如果您不想在 Debug模式下运行,请查看 this issue .
    资料来源:
  • How to build and run C++ code in Visual Studio Code?
  • 很棒的教程(对于 ubuntu,使用 VSCode-gfortran-Win10 为我工作)
    https://www.youtube.com/watch?v=Rj-kYb9nZ3g&ab_channel=LukasLamm .
  • 关于visual-studio-code - 如何在VSCODE中设置tasks.json文件来编译Fortran程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68638271/

    相关文章:

    visual-studio-code - Visual Studio Code 显示运行完成后在控制台行上运行的最后一个命令

    javascript - React Router 如何从路径字符串中推断强类型参数?

    typescript - 如何调试在 vscode/vs2015 中使用 webpack 捆绑的 typescript 代码

    asp.net - DNU 在 OSX Yosemite 上恢复未知 header

    string - 为什么 GDB 认为我的 Fortran 字符串是 ~4GiB

    visual-studio-code - 如何在 Visual Studio Code 中更改浏览器

    c++ - Visual Studio 中的调用约定

    linker - ifort在Linux上的编译器选项

    arrays - 初始化参数序列和参数数组之间有区别吗?

    c - 如何将动态分配的数组传递给子例程