vscode gfortran debug配置

文章介绍了如何在VisualStudioCode中设置预编译任务(preLaunchTask)以使用GDB对Fortran代码进行调试,包括tasks.json和launch.json文件的配置细节。
摘要由CSDN通过智能技术生成

先编译以后(preLaunchTask)才能用gdb debug。

  • 生成tasks.json文件:编译ctrl shift pTasks: Config TaskCreate tasks.json file from templateOthers
{
    "version": "2.0.0",
    "tasks": [
        {
        //If `shell` is specified, the command is interpreted as a shell command
            "type": "shell", 
            "label": "gfortran build",
            "command": "gfortran",
            "args": [
              "-fdiagnostics-color=always",
              "${file}",
              "-g3", // 生成调试信息,-g3最高级别
              "-O0", // 关闭优化,编译时间短,适合调试阶段
              "-fbacktrace", // 堆栈回溯信息
              "-fcheck=all", // 所有运行时检查
              "-Wall", // 启用所有警告
              "-Wextra", // 启用额外的警告
              "-Warray-temporaries", // 数组临时变量警告
              "-Wconversion", // 类型转换警告
              "-ffree-line-length-0", // 支持无限制的自由格式行长度
              "-o", // 目标名称
              "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "group": { 
              "kind": "build", 
              "isDefault": true // 默认task
            },
            "options": {
              "cwd": "${fileDirname}"
            },
            "detail": "Task generated by Debugger."
        }
    ]
}
  • 创建launch.jsondebug
{
  // 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) Fortran",
      "type": "cppdbg",
      "request": "launch",
      "preLaunchTask": "gfortran build",
      "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
      "args": [], // Possible input args for a.out
      "stopAtEntry": false,
      "cwd": "${fileDirname}", // the task runner's current working directory
      "environment": [],
      "externalConsole": false,
      "MIMode": "gdb",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true,
        },
      ],
    },
  ],
}

参考链接:

  • https://marketplace.visualstudio.com/items?itemName=fortran-lang.linter-gfortran#debugging
  • https://submit.mit.edu/submit-users-guide/tutorials/tutorial_5.html
  • https://code.visualstudio.com/docs/editor/debugging
  • https://code.visualstudio.com/docs/editor/tasks
  • https://code.visualstudio.com/docs/cpp/config-mingw
  • https://cs.pynote.net/sf/c/cdm/202111137/#_1
  • https://zhuanlan.zhihu.com/p/513148985
  • 7
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VSCode配置使用Fortran需要以下步骤: 1. 首先,你需要下载并安装VSCode。你可以从官方网站上下载适用于你的操作系统的安装程序。 2. 安装Fortran环境。你可以选择安装GNU Fortran编译器(gfortran)或者其他Fortran编译器。安装方法因操作系统而异。 3. 在VSCode中安装Fortran相关插件。你可以在VSCode的扩展商店中搜索并安装Fortran插件。推荐安装的插件包括Fortran、Modern FortranFortran IntelliSense、Code Runner和Fortran Breakpoint Support。其中,Fortran Breakpoint Support插件是必需的,其他插件可以根据需要进行选择安装。 4. 配置VSCode以使用Fortran。在VSCode的设置中,你可以设置Fortran编译器的路径和其他相关配置。具体设置方法可以参考插件的文档或者官方文档。 5. 编写第一个Fortran程序。在VSCode中创建一个新的Fortran文件,编写你的Fortran代码。你可以使用插件提供的代码高亮和自动补全功能来辅助编写代码。 如果在配置过程中遇到问题,可以参考相关插件的文档或者在社区中寻求帮助。另外,如果在使用gfortran时出现问题,可能是因为系统环境变量没有正确配置。你可以将gfortran.exe所在的文件夹添加到系统环境变量中,以确保系统可以正确识别gfortran命令。例如,将gfortran.exe所在的文件夹路径(比如C:\cygwin64\bin)添加到系统环境变量中。 希望以上信息对你有帮助! #### 引用[.reference_title] - *1* *2* *3* [Fortran编程:VScode配置](https://blog.csdn.net/wokaowokaowokao12345/article/details/127076563)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值