WIndows下VSCode搭建Fortran环境

Windows下VSCode搭建Fortran环境

1. 下载VSCode

下载地址: https://code.visualstudio.com/Download

下载然后一路安装即可

2. 下载MinGW-W

下载地址: https://sourceforge.net/projects/mingw-w64/files/Toolchains targetting Win64/Personal Builds/mingw-builds/

WIndows下VSCode搭建Fortran环境

下载之后解压记住路径.

例如我放在: C:\environment\mingw64

3. 搭建环境变量

  1. 打开环境变量

    WIndows下VSCode搭建Fortran环境
    WIndows下VSCode搭建Fortran环境
    ? 即在系统变量中加入: C:\environment\mingw64\bin

    ? 注意: 结合自己的路径.

  2. 测试是否成功

    打开cmd, 输入gcc , 显示如下, 则配置成功

    WIndows下VSCode搭建Fortran环境

4. 编写Fortran代码

  1. 打开VSCode, 并新建文件

    WIndows下VSCode搭建Fortran环境

    program projectName
        implicit none
        print *, "Hello world"
        !fortran语言注释 pause写上, 运行窗口不闪退
        pause
    end program projectName
    
  2. 写代码环境才能运行

    在当前项目下新建文件夹:.vscode

    在该文件夹下,新建文件: launch.json 复制以下代码在该文件

    {
        "version": "0.0.1",
        "configurations": [
            
    
    
            {
                "name": "Fortran Launch (GDB)",
                "type": "cppdbg",
                "request": "launch",
                "targetArchitecture": "x86",
                "program": "${workspaceRoot}\\${fileBasenameNoExtension}.exe",
                "MIMode": "gdb",
                "miDebuggerPath": "C:/environment/mingw64/bin/gdb.exe",//结合自己的路径!
                "args": [],
                "stopAtEntry": false,
                "cwd": "${workspaceRoot}",
                "externalConsole": true,
                "preLaunchTask": "gfortran"
            },
            {
                "name": "Intel Debug Attach",
                "type": "cppvsdbg",
                "request": "attach",
                "processId": "${command:pickProcess}"
            }
        ] }
    

    注意: "miDebuggerPath": "C:/environment/mingw64/bin/gdb.exe" 这是我的mingw64路径

    在该文件夹下,新建文件: tasks.json 复制以下代码在该文件

    {
        "version": "2.0.0",
        "command": "gfortran",
        "args": [
            "-g",
            "${file}",
            "-o",
            "${workspaceRoot}\\${fileBasenameNoExtension}.exe"
        ],
        "presentation": {
            "echo": true,
            "reveal": "always",
            "focus": false,
            "panel": "new", //这里shared表示共享,改成new之后每个进程创建新的端口
            "showReuseMessage": true,
            "clear": false
        }
    }
    
  3. 运行代码

    WIndows下VSCode搭建Fortran环境

    成功!

    以后新建新的Fortran项目, 将 .vscode文件夹复制到别的项目下即可

WIndows下VSCode搭建Fortran环境

上一篇:学习zepto.js(对象方法)[5]


下一篇:c#字符串切割