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安装

相关推荐
hdsoft_huge1 小时前
Java & Spring Boot常见异常全解析:原因、危害、处理与防范
java·开发语言·spring boot
风中的微尘1 小时前
39.网络流入门
开发语言·网络·c++·算法
未来之窗软件服务2 小时前
幽冥大陆(二)RDIFSDK 接口文档:布草洗涤厂高效运营的技术桥梁C#—东方仙盟
开发语言·c#·rdif·仙盟创梦ide·东方仙盟
小冯记录编程2 小时前
C++指针陷阱:高效背后的致命危险
开发语言·c++·visual studio
1uther3 小时前
Unity核心概念⑨:Screen
开发语言·游戏·unity·c#·游戏引擎
C_Liu_3 小时前
C++:类和对象(下)
开发语言·c++
coderxiaohan3 小时前
【C++】类和对象1
java·开发语言·c++
用户21411832636023 小时前
Qwen3-Coder 实战!历史人物短视频一键生成,多分镜人物不崩,魔搭直接玩
后端
追逐时光者3 小时前
C#/.NET/.NET Core技术前沿周刊 | 第 54 期(2025年9.8-9.14)
后端·.net
追逐时光者3 小时前
C#/.NET/.NET Core编程技巧练习集,配套详细的文章教程讲解!
后端·.net