【问题标题】:Could not run debugger for fortran. Visual Studio Code无法为 fortran 运行调试器。视觉工作室代码
【发布时间】:2019-01-22 18:17:03
【问题描述】:

我正在尝试在 Visual Studio 代码(ubuntu 18.04)上调试一个 fortran 文件。

我安装了以下扩展程序

我的launch.json文件如下

"version": "0.0.1",
"configurations": [
    {
        "name": "Fortran Launch (GDB)",
        "type": "cppdbg",
        "request": "launch",
        "targetArchitecture": "x86",
        "program": "${workspaceRoot}/./a.out",
        "miDebuggerPath": "gdb",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceRoot}",
        "externalConsole": true,
        "preLaunchTask": "gfortran"
    }
]

因为我使用的是 linux,所以我不需要给出 gfortran 的路径。我还尝试通过将 .exe 更改为 linux 扩展来稍微更改 launch.json。我已经在问题中更新了它。但是调试器仍然没有运行并在控制台中给出以下错误

and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
=cmd-param-changed,param="pagination",value="off"
Stopped due to shared library event (no libraries added or removed)
Loaded '/lib64/ld-linux-x86-64.so.2'. Symbols loaded.
Breakpoint 1, 0x0000555555554a60 in main ()
[Inferior 1 (process 24472) exited normally]
The program '/home/m/gSoC/GasSimulator/./a.out' has exited with code 0 (0x00000000).

【问题讨论】:

  • 我几个月来一直在尝试让 VScode 运行 fortran 代码,但没有成功。如果它对你有用,你可以在这里添加相同的指针吗?不是调试器,只是运行一个简单的代码。
  • @jmh 我不确定这是否是你想要的,但我在 VS 代码中从终端控制台编译了代码并做了一个./a.out 以在 VS Code 内的终端中正常运行它。

标签: debugging visual-studio-code fortran gdb gfortran


【解决方案1】:

为了将来参考,我遇到了同样的问题,通过将 -g 选项传递给编译器来解决它

【讨论】:

  • @Nil 去年的综合回答以及其他建议涵盖了这一点。
  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
【解决方案2】:

我不知道如何解决您的具体问题,但这里我是如何在 Visual Studio Code 中调试 Fortran 程序的。

  1. 我安装了 3 个插件:“C/C++”、来自 Xavier Hahn 的“fortran”和“Fortran Breakpoint Support”
  2. 我按照fortranwiki.org 的建议编译了我的程序。
gfortran SOME FORTRAN FILES -g -Wall -Wextra -Warray-temporaries -Wconversion -fimplicit-none -fbacktrace -ffree-line-length-0 -fcheck=all -ffpe-trap=zero,overflow,underflow -finit-real=nan
  1. 我生成了一个launch.json 文件,只更改了我的程序路径和参数,没有别的。这给出了类似的东西
    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "(gdb) Lancer",
                "type": "cppdbg",
                "request": "launch",
                "program": "${workspaceFolder}/a.out",    // <-- Change this
                "args": [],                               // <-- Change this
                "stopAtEntry": false,
                "cwd": "${workspaceFolder}",              // <-- And maybe this
                "environment": [],
                "externalConsole": false,
                "MIMode": "gdb",
            }
        ]
    }

也许在 2018 年是不可能或超级难做到的,谁知道呢?从那时起,VSCode 及其插件已经有了很多更新。

【讨论】:

    【解决方案3】:

    转到代码/首选项菜单项下的设置,然后在出现的搜索框中输入 fortran。你会看到一行写着:"fortran.gfortranExecutable": "gfortran",

    该行的标题为: // 指定 gfortran 可执行文件的完整路径。

    因此,请尝试将 gfortran 更改为您在终端命令行上键入 which gfortran 时得到的响应。

    您可能还想将 json 文件中的“preLaunchTask”变量更改为 gfortran 路径。

    【讨论】:

    • 因为我使用的是linux,所以我不需要给出gfortran的路径。我还尝试通过将 .exe 更改为 linux 扩展来稍微更改 launch.json。我已经在问题中更新了它。但是调试器仍然没有运行并在控制台中给出以下错误
    猜你喜欢
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 2016-09-20
    • 2020-07-18
    • 2018-07-05
    • 2015-07-10
    相关资源
    最近更新 更多