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

相关推荐
季风11323 小时前
10.对象关系行为
后端
神明不懂浪漫3 小时前
【第八章】多线程(一)
java·开发语言·经验分享·笔记
tann3 小时前
Environment类
后端
鲸鹏芯海微电子科技上海有限公司3 小时前
手机直连卫星,射频前端到底要解决什么?
前端·后端
开心就好20254 小时前
通配符 Bundle ID 和精确 Bundle ID 怎么选,推送、iCloud 能不能用通配符
后端·ios
测试员周周4 小时前
【agent评测】:真实系统演示工具调用长什么样,用例怎么设计,怎么测
前端·后端·github
宇先生本人号4 小时前
别再用“AI 说完成了”:一套可复算的 Agent 验收流水线
后端
yiangL_4 小时前
1、Python 输入输出实验|print 与 input 人机交互实践
开发语言·python·人机交互
张明君644514 小时前
在 Astro SSR 项目中实现服务启动前初始化
前端·后端
用户3721574261354 小时前
Java 删除 Excel 重复行:整行去重、按单列和多列去重
后端