rust 1.安装

安装

下载地址:https://www.rust-lang.org/learn/get-started

rust安装有一个先决条件:cpp的编译器

在windows下进行Rust开发,编译器有两个选择要么是msvc,要么是MinGW(GNU)。这是两个是不兼容的编译器,用了msvc编译的库,那么这个库也只能引用msvc编译的依赖库;gnu也是一样。

既然在windows下编写,仍然建议使用msvc编译器。如果你已经出现两个版本了请先卸载rust,再重新安装

shell 复制代码
shellrustup self uninstall

安装完成后,查看rust版本:rustc --version

开发

VS Code 2022

插件:rust-analyzer

Hello World

shell 复制代码
> mkdir hello_world
> cd hello_world
> code .

进入vscode创建main.rs文件

rust 复制代码
fn main() {
  println!("Hello World!");
}

ctrl+~唤醒terminal,编译main.rs

shell 复制代码
rustc main.rs

编译后就会生成main.exe可执行文件

shell 复制代码
> .\main.exe
Hello World!

编译异常

如果在rustc编译的时候出现以下异常

shell 复制代码
> rustc .\main.rs
error: linker `link.exe` not found
  |
  = note: program not found

note: the msvc targets depend on the msvc linker but `link.exe` was not found

note: please ensure that Visual Studio 2017 or later, or Build Tools for Visual Studio were installed with the Visual C++ option.

note: VS Code is a different product, and is not sufficient.

error: aborting due to 1 previous error

是因为缺少了windows SDK或msvc build tools 可以通过vs install安装

相关推荐
喵手7 分钟前
Java中的HashMap:你了解它的工作原理和最佳实践吗?
java·后端·java ee
Gavin_91511 分钟前
一文速通Ruby语法
开发语言·ruby
冷月半明20 分钟前
把离线 Python 项目塞进 Docker:从 0 到 1 的踩坑实录,一口气讲透 10 个最常见困惑
后端
搞一搞汽车电子22 分钟前
vs studio 2017项目不支持studio vs2022
开发语言
用户2986985301428 分钟前
如何使用 Spire.Doc 在 Word 中查找和替换文本?
后端
宫水三叶的刷题日记38 分钟前
真的会玩,钉钉前脚辟谣高管凌晨巡查工位,小编随后深夜发文
前端·后端·面试
天天摸鱼的java工程师38 分钟前
Go 语言未来会取代 Java 吗?
java·后端
witkey_ak989639 分钟前
python 可迭代对象相关知识点
开发语言·python
野犬寒鸦1 小时前
力扣hot100:最大子数组和的两种高效方法:前缀和与Kadane算法(53)
java·后端·算法
AAA修煤气灶刘哥1 小时前
《从 0 到 1 上手:RBAC+SpringSecurity 权限管理教程》
java·后端·安全