0


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

查看活动工具链


本文转载自: https://blog.csdn.net/yilun/article/details/130871565
版权归原作者 wufeng无峰 所有, 如有侵权,请联系我们删除。

“Rust环境搭建以及vscode调试环境配置”的评论:

还没有评论