Rust报错:the msvc targets depend on the msvc linker but `link.exe` was not found

当我在我的 windows 电脑上安装 rust,然后用 cargo 新建了一个项目后,cargo run 会报错:

shell 复制代码
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: could not compile `minigrep` (bin "minigrep") due to previous error

这个报错是 C 的编译器引起的,这里我见到了几种常见的解决方法(我用最后一种方法成功解决了问题):

  1. 下载安装 Visual Studio 2019 的构建工具,但是显然,下一个这玩意需要很大内存。但是这种方法确实是比较正宗的解决方法,一般不会有幺蛾子。记得选C++ 工具

  2. 这个错误可能是因为使用GCC编译,需要顺序执行,修复一下:

    • rustup uninstall toolchain stable-x86_64-pc-windows-msvc
    • rustup toolchain install stable-x86_64-pc-windows-gnu
    • rustup default stable-x86_64-pc-windows-gnu
  3. Microsoft C++ 生成工具 安装一下,记得选上下面这几个

  4. 这种方法最简单,因为不用安装很多东西占很多内存,也没有繁琐的步骤:

    直接执行:
    rustup default stable-x86_64-pc-windows-gnu

相关推荐
勤劳的进取家5 分钟前
传输层基础
运维·开发语言·学习·php
wangbing11258 分钟前
Java处理csv文件总是丢数据
java·开发语言·python
Rust语言中文社区9 分钟前
【Rust日报】2026-04-28 Pacquet:pnpm 的 Rust 重写版本
开发语言·后端·rust
modelmd17 分钟前
研究C语言的hello world输出
c语言·开发语言·chrome
小小199220 分钟前
vue 单页面请求
开发语言·前端·javascript
hhb_61820 分钟前
JavaScript 本地存储与动态数据渲染实战案例
开发语言·javascript·ecmascript
淀粉肠kk27 分钟前
【C++11】智能指针详解
开发语言·c++
Hungry_Shark28 分钟前
Windows上Docker安装失败:DockerDesktop must beowned by an elevated account
windows·docker
书源丶31 分钟前
三十二、Java集合(一)——Collection与List全家桶
java·windows·list
一个人旅程~32 分钟前
Win旧版或win10部分版本如何解除260字符长路径名限制?
linux·windows·经验分享·电脑