windows系统下Rust环境搭建以及vscode调试环境配置

下载链接

Rust 编译工具:https://www.rust-lang.org/zh-CN/tools/install

Visual Studio Code:https://code.visualstudio.com/Download

安装 Rust 编译工具

Rust的编译工具依赖C语言的编译工具。如果使用Linux系统,需要安装GCC或clang。如果使用macOS,需要安装Xcode。如果使用Windows系统,需要安装Visual Studio 2013以上的环境以使用MSVC或安装MinGW+GCC编译环境。下面主要讲Windows下的安装。

下载好的 Rustup 在 Windows 上是一个可执行程序 rustup-init.exe。

推荐使用微软的VS IDE,输入1,继续安装。会直接进入MSVC下载安装界面,点击安装后,等待安装完成。MSVC安装完成后继续安装rustup。

执行如下命令检查测试:

rustc -V

 搭建 VSCode 开发环境

安装插件rust-analyzer和Native Debug

在.vscode目录创建tasks.json文件,用来配置cargo(rust构建工具)

{ 
    "version": "2.0.0", 
    "tasks": [ 
        { 
            "label": "build", 
            "type": "shell", 
            "command":"cargo", 
            "args": ["build"] 
        } 
    ] 
}

在.vscode里面生成launch.json文件,指定关联调试的生成执行文件

{
    "version": "0.2.0", 
    "configurations": [ 
        { 
            "name": "(Windows) 启动", 
            "preLaunchTask": "build", 
            "type": "cppvsdbg", 
            "request": "launch", 
            "program": "${workspaceFolder}/target/debug/${workspaceFolderBasename}.exe", 
            "args": [], 
            "stopAtEntry": false, 
            "cwd": "${workspaceFolder}", 
            "environment": [], 
            "console": "integratedTerminal" 
        }, 
        { 
            "name": "(gdb) 启动", 
            "type": "cppdbg", 
            "request": "launch", 
            "program": "${workspaceFolder}/target/debug/${workspaceFolderBasename}.exe", 
            "args": [], 
            "stopAtEntry": false, 
            "cwd": "${workspaceFolder}", 
            "environment": [], 
            "externalConsole": false, 
            "MIMode": "gdb", 
            "miDebuggerPath": "这里填GDB所在的目录", 
            "setupCommands": [ 
                { 
                    "description": "为 gdb 启用整齐打印", 
                    "text": "-enable-pretty-printing", 
                    "ignoreFailures": true 
                } 
            ] 
        } 
    ] 
}

问题汇总

1. 如何判断Rust编译器使用的是哪个Windows工具链?

   使用rustup show查看活动工具链

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wufeng无峰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值