在VSCode中使用Compaq Visual Fortran编译运行Frotran程序

本片文章主要是为了使用VSCode编译运行带QuickWin库的老版本Fortran代码。

一、准备工作

安装VSCode和Compaq Visual Fortran6.6,相关安装方法在网上找。

二、配置Fortran工程

用VSCode打开保存有Frotran代码的文件夹

建立.vscode文件夹,建立launch.json和task.json文件,分别复制下面的脚本:

launch.json

{
    // 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.0.1",
    "configurations": [
        {
            "name": "Fortran Launch (GDB)",
            "type": "cppdbg",
            "request": "launch",
            "targetArchitecture": "x86",
            "program": "${workspaceRoot}\\Debug\\Test.exe",
            "miDebuggerPath": "D:\\Soft\\mingw64\\bin\\gdb.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "externalConsole": true,
            "preLaunchTask": "Build"
        },
        {
            "name": "Intel Debug Attach",
            "type": "cppvsdbg",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

task.json 

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build",
            "type": "shell",
            "command": "C:\\Program Files\\Microsoft Visual Studio\\DF98\\Bin\\DFVARS.BAT" ,
            "args": [
                "&",
                "DF.EXE",
                "/check:bounds",
                "/compile_only",
                "/dbglibs",
                "/debug:full",
                "/libs:qwins",
                "/nologo",
                "/traceback",
                "/warn:argument_checking",
                "/warn:nofileopt",
                "/module:'Debug\\'",
                "/object:'Debug\\'",
                "/pdbfile:'Debug\\DF60.PDB'",
                ".\\test1.f90",
                ".\\test2.f90",
                ".\\test3.f90"
                "&",
                "Link.exe",
                "kernel32.lib",
                "/nologo",
                "/entry:WinMainCRTStartup",
                "/subsystem:windows",
                "/incremental:no",
                "/pdb:Debug\\Test.pdb",
                "/debug",
                "/machine:I386",
                "/nodefaultlib:dfconsol.lib",
                "/out:Debug\\Test.exe",
                "/pdbtype:sept",
                ".\\Debug\\test1.obj",
                ".\\Debug\\test2.obj",
                ".\\Debug\\test3.obj"
            ],
            "group": "build",
            "presentation": {
                // Reveal the output only if unrecognized errors occur.
                "reveal": "silent"
            },
            // Use the standard MS compiler pattern to detect errors, warnings and infos
            "problemMatcher": "$msCompile"
        }
}

test1~testn.f90是对应的Fortran代码文件,根据自己的工程进行修改。

编译中需要注意的4个地方:

1.运行CVF编译器前,要运行DFVARS.BAT进行lib库路径等环境变量设置。

2.Fortran的编译程序DF.exe命令行设置,完整的命令行参数如下:

DF.EXE /check:bounds /compile_only /dbglibs /debug:full /libs:qwins /nologo /traceback /warn:argument_checking /warn:nofileopt /module:'Debug\\' /object:'Debug\\' /pdbfile:'Debug\\DF60.PDB'

3.Fortran的连接程序Link.exe命令行设置(与C++的连接是一样的)。完整的命令行参数如下:

Link.exe kernel32.lib /nologo /entry:WinMainCRTStartup /subsystem:windows /incremental:no /pdb:Debug\\Test.pdb /debug /machine:I386 /nodefaultlib:dfconsol.lib /out:Debug\\Test.exe /pdbtype:sept 

4.一行命令中含多条指令要用”&“连接,这个是Command Prompt的语法格式,PowerShell不支持,所以在进行编译前,需要把VSCode的终端改成Command Prompt,默认是PowerShell。

三、编译和链接

做完以上两步后,点击Terminal-> Run Build Tasks即可执行task.json中的编译脚本。输出文件在当前文件夹下的Debug文件夹。

四、运行

点击Run-> Start Debugging,即可运行。

 事实上,使用CVF(Compaq Visual Fortran)编译后,会产生pdb文件,但gdb.exe并不兼容这种格式调式符号,所以是无法调试的,运行Start Debugging和Run Without Debugging效果一样。

有哪位客官知道怎么在VScode中使用Windbg,还望不吝赐教。

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值