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配置完成,我们运行下程序,结果如图:

相关推荐
uppp»22 分钟前
深入理解 Java 反射机制:获取类信息与动态操作
java·开发语言
玩电脑的辣条哥2 小时前
Python如何播放本地音乐并在web页面播放
开发语言·前端·python
ll7788115 小时前
LeetCode每日精进:20.有效的括号
c语言·开发语言·算法·leetcode·职场和发展
Jackson@ML7 小时前
Python数据可视化简介
开发语言·python·数据可视化
赵琳琅7 小时前
Java语言的云计算
开发语言·后端·golang
lly2024067 小时前
jQuery 杂项方法
开发语言
鸡啄米的时光机7 小时前
vscode的一些实用操作
vscode·学习
赵琳琅7 小时前
MDX语言的安全开发
开发语言·后端·golang
开开又心心的学嵌入式7 小时前
C语言——指针进阶应用
c语言·开发语言
开开又心心的学嵌入式7 小时前
C语言——指针基础知识
c语言·开发语言