windows下 Rust 环境配置
2022/7/21 5:24:58
本文主要是介绍windows下 Rust 环境配置,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
搭建 Visual Studio Code 开发环境
首先,需要安装最新版的 Rust 编译工具和 Visual Studio Code。
Rust 编译工具:https://www.rust-lang.org/zh-CN/tools/install
Visual Studio Code:https://code.visualstudio.com/Download
Rust 的编译工具依赖 C 语言的编译工具,这意味着你的电脑上至少已经存在一个 C 语言的编译环境。如果你使用的是 Linux 系统,往往已经具备了 GCC 或 clang。如果你使用的是 macOS,需要安装 Xcode。如果你是用的是 Windows 操作系统,你需要安装 Visual Studio 2013 或以上的环境(需要 C/C++ 支持)以使用 MSVC 或安装 MinGW + GCC 编译环境(Cygwin 还没有测试)。
安装 Rust 编译工具
安装初始向导
如果没有Visual Studio环境使用1进行快速安装
安装完成后会进入如下的界面,按1继续安装,接下来这个向导会自动安装rust和cargo包管理器
安装成功后可以使用rustc -V
来查看rust版本,如下图所示,已经安装完成
安装rust-analyzer和Native Debug
重新启动 VSCode,Rust 的开发环境就搭建好了。
第一个rust应用
$ cargo new hello_world $ cd hello_world
项目结构
├─.gitignore ├─Cargo.toml ├─result.txt ├─src | └main.rs
运行
cargo run
运行结果
$ cargo run Compiling hello_world v0.1.0 (F:\项目\rust-demo\hello_world) Finished dev [unoptimized + debuginfo] target(s) in 0.26s Running `target\debug\hello_world.exe` Hello, world!
上述代码,cargo run
首先对项目进行编译,然后再运行,因此它实际上等同于运行了两个指令,下面我们手动试一下编译和运行项目:
编译
$ cargo build Finished dev [unoptimized + debuginfo] target(s) in 0.00s
运行
$ ./target/debug/world_hello Hello, world!
但是上述也只是debug模式下的编译,发布版本release应该这样做吗,添加 --release
来编译:
cargo run --release
cargo build --release
这篇关于windows下 Rust 环境配置的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?