Vscode、cygwin或simply fortran配置gfortran及GCC

通过cygwin配置环境

以前这么弄还行,现在这么搞c没问题,fortran能编译不能调试,老说有个库调不了,可能装的环境少了,建议看最下面simply fortran办法

一、通过cygwin安装相关编译器

    安装devel下的:gcc-core, gcc-fortran, gcc-g++, gdb,保证版本一致

cygwin安装完成后,将bin文件夹添加到系统环境变量PATH

二、Vscode插件安装

    依次安装c/c++、fortran、Fortran Breakpoint Support插件

三、配置C++

调试选GDB,要求配置launch.json

 {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "g++.exe build and debug active file",
                "type": "cppdbg",
                "request": "launch",
                "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "args": [],
                "stopAtEntry": false,
                "cwd": "${workspaceFolder}",
                "environment": [],
                "externalConsole": true,      //修改此项,让其弹出终端
                "MIMode": "gdb",
                "miDebuggerPath": "C:\\software\\cygwin\\bin\\gdb.exe",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ],
                "preLaunchTask": "task g++" //修改此项
            }
        ]
    }

task.json

{
        "version": "2.0.0",
        "tasks": [
            {
                "type": "shell",
                "label": "task g++",    
                "command": "C:\\software\\cygwin\\bin\\g++.exe", //修改此项
                "args": [
                    "-g",
                    "${file}",
                    "-o",
                    "${fileDirname}\\${fileBasenameNoExtension}.exe"
                ],
                "options": {
                    "cwd": "C:\\software\\cygwin\\bin"  //修改此项
                },
                "problemMatcher": [
                    "$gcc"
                ],
                "group": "build"
            }
        ]
    }

调试报错,不能打开源文件,在报错出点小灯泡-编译器路径

路径如

C:\software\cygwin\bin\g++.exe

并按照提示修改IntelliSense 模式为linux-gcc-x64

四、配置gfortran

调试选GDB,要求配置launch.json

{
    "version": "0.0.1",
    "configurations": [
        {
            "name": "Fortran Launch (GDB)",
            "type": "cppdbg",
            "request": "launch",
            "targetArchitecture": "x86",
            "program": "${workspaceRoot}\\${fileBasenameNoExtension}.exe",
            "miDebuggerPath": "gdb.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "externalConsole": true,
            "preLaunchTask": "gfortran"
        },
        {
            "name": "Intel Debug Attach",
            "type": "cppvsdbg",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ] }

在.vscode内新建tasks.json

内容如下

{
    "version": "2.0.0",
    "command": "gfortran",
    "args": [
        "-g",
        "${file}",
        "-o",
        "${workspaceRoot}\\${fileBasenameNoExtension}.exe"
    ]
}

F5启动调试即可

通过simply fortran配置环境

simply fortran安装之后会自动配置好gcc、gfortran、gdb等环境,虽然软件要钱,但环境不要钱,白嫖一波,

配置文件同cygwin配置情况,

注意修改miDebuggerPath的路径就行了

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值