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

相关推荐
一只大袋鼠18 分钟前
Git 进阶(二):分支管理、暂存栈、远程仓库与多人协作
java·开发语言·git
LuminousCPP1 小时前
数据结构 - 线性表第四篇:C 语言通讯录优化升级全记录(踩坑 + 思考)
c语言·开发语言·数据结构·经验分享·笔记·学习
web3.08889991 小时前
1688 图搜接口(item_search_img / 拍立淘) 接入方法
开发语言·python
один but you2 小时前
从可变参数到 emplace:现代 C++ 性能优化的核心组合
java·开发语言
IT_陈寒2 小时前
Redis缓存击穿把我整不会了,原来还有这手操作
前端·人工智能·后端
kyriewen2 小时前
面试官让我查各部门工资最高的员工,我用AI三秒写出窗口函数,他愣了
后端·mysql·面试
文心快码BaiduComate3 小时前
干货|Comate Harness Engineering工程实践指南
前端·后端·程序员
光辉GuangHui3 小时前
Agent Skill 也需要测试:如何搭建 Skill 评估框架
前端·后端·llm
MY_TEUCK3 小时前
【Java 后端 | Nacos 注册中心】微服务治理原理、选型与注册发现实战
java·开发语言·微服务
我是谁的程序员3 小时前
Mac 上生成 AppStoreInfo.plist 文件,App Store 上架
后端·ios