RUST 新手环境搭建(Windows10 环境下 vscode + rust配置) 备注:新手上路
备注:新手上路
前言
提示:新手入坑,大家相互学习。
一、准备
Rust 编译工具:https://www.rust-lang.org/zh-CN/tools/install
Visual Studio Code:https://code.visualstudio.com/Download
C++ build tools:https://visualstudio.microsoft.com/zh-hans/thank-you-downloading-visual-studio/?sku=BuildTools&rel=16 (防止出现:Error: linker link.exe
not found 踩坑)
二、安装步骤
1.安装RUST
执行 rustup-init 文件: 安装 MSVC (推荐),输入 1 并回车
等待安装完毕:左下角开始->运行 打开 输入 cmd :
输入:rustc -V 回车
2.安装VScode
此处省略
3.安装C++ build tools
选择C++的桌面开发 :右边选择三项就可以了
总结
提示:以上安装基本完成,成功了一半。
三、配置VScode + rust
先安装一些扩展:这是我个人安装vscode 扩展,仅供参考(C/C++插件必须)
要不然会报错:
文件目录结构如下:
在 VSCode 中打开新建的greeting文件夹:新建一个 **.vscode**
文件夹
文件夹中新建两个文件:**launch.json**
**tasks.json**
**tasks.json**
:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command":"cargo",
"args": ["build"]
}
]
}
**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": [],
"externalConsole": false
},
{
"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
}
]
}
]
}
保存!
四、准备工作完毕:启动!
新建一个终端:
因为我们打开的是greeting 这个文件夹,就不用跟跟学习网站一样 cd ./greeting
直接
PS E:\mywork\rust\greeting> cargo build
PS E:\mywork\rust\greeting> cargo run
完毕!