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

相关推荐
xwlcfyb5 分钟前
零基础学好C语言系列第八讲:初识指针
c语言·开发语言
非 白7 分钟前
【Java分布式】Nacos注册中心
java·开发语言·nacos·注册中心
88号技师8 分钟前
2025年2月最新SCI-鹰鱼优化算法HawkFish Optimization Algorithm-附Matlab免费代码
开发语言·算法·matlab·优化算法
吃海鲜的骆驼12 分钟前
服务异步通讯与RabbitMQ
java·分布式·后端·rabbitmq
m0_7482336414 分钟前
RabbitMQ 进阶
android·前端·后端
m0_7482386323 分钟前
Spring Boot项目接收前端参数的11种方式
前端·spring boot·后端
桦说编程25 分钟前
【硬核总结】如何轻松实现只计算一次、惰性求值?良性竞争条件的广泛使用可能超过你的想象!String实际上是可变的?
后端·函数式编程
Joey_friends1 小时前
【Linux】线程详解
开发语言
_GR1 小时前
Qt开发⑧Qt的窗口_下_浮动窗口+对话框
开发语言·css·c++·qt·microsoft
Good Note1 小时前
Golang——常用库context和runtime
开发语言·爬虫·golang