windows下rust调试运行环境部署

1,rust编译环境安装

    在联网环境下,建议使用rustup-init.exe程序安装(本文使用的改模式)

    选择1“默认"进行安装,默认安装x86_64-pc-windows-msvc

    在安装完成后,后续为了配置gbd调试,也安装上x86_64-pc-windows-gnu

    命令如下:

    rustup default stable-x86_64-pc-windows-gnu

    rustup toolchain install stable-x86_64-pc-windows-gnu

2,vs code环境配置

    第一步:先安装vs code,本文下载最新的版本VSCodeUserSetup-x64-1.84.2.exe

    第二步:安装完成后,下载相应的插件

    c/c++插件必须要安装,不然在配置调试运行时会找不到对应的(cppvsdbg)和(cppdbg)

    其他比较重要的插件如: rust-analyzer,Rust syntax,Native debug;这些自己看着装

3,配置运行rust程序

    命令行进入自己的rust目录,然后生成第一个rust程序:

    cd d:\rust(路径依据自己工程目录来)

    cargo new learn

    cargo build

    在vs code中配置运行环境:

    首先构建配置文件配置:

     我们选择rust: cargo build,这个时候会让我们配置tasks.json配置文件,我们配置内容如下:

{

    "version": "2.0.0",

    "tasks": [

       {

            "label": "build",

            "type": "shell",

            "command": "cargo",

            "args": ["build"]

        }

    ]

}

    接着我们配置运行环境: 

    我们在运行调试中,打开launch.json配置文件。

    配置文件中我们配置两个选项:C/C++:(Windows)启动和C/C++:(gdb)启动

    具体配置信息如下:

{

    // 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) 启动",

            "type": "cppdbg",

            "request": "launch",

            "program": "${workspaceFolder}/target/debug/${workspaceFolderBasename}.exe",

            "args": [],

            "stopAtEntry": false,

            "cwd": "${fileDirname}",

            "environment": [],

            "externalConsole": false,

            "MIMode": "gdb",

            "miDebuggerPath": "/path/to/gdb",

            "setupCommands": [

                {

                    "description": "为 gdb 启用整齐打印",

                    "text": "-enable-pretty-printing",

                    "ignoreFailures": true

                },

                {

                    "description": "将反汇编风格设置为 Intel",

                    "text": "-gdb-set disassembly-flavor intel",

                    "ignoreFailures": true

                }

            ]

        },

       

       

   

        {

            "type": "cppvsdbg",

            "preLaunchTask": "build",

            "request": "launch",

            "name": "windows run",

            "program": "${workspaceFolder}/target/debug/${workspaceFolderBasename}.exe",

            "args": [],

            "cwd": "${workspaceRoot}",

            "stopAtEntry": false,

            "environment": [],

            "externalConsole": false

        }

    ]

}

     至此,vs code的rust运行环境windows配置完成,我们运行下程序,结果如图:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值