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

相关推荐
陈eaten4 分钟前
windows上协调多版本python以及虚拟环境
开发语言·windows·python·pycharm·pip·虚拟环境·py
一晌小贪欢8 分钟前
告别 `datetime` 混乱:使用 Python 类型注解构建健壮的时间处理管道
开发语言·python·时间·时间类型·时间模块
yaoxin52112314 分钟前
401. Java 文件操作基础 - 使用 Buffered Stream I/O 写入文本文件
java·开发语言·python
MandalaO_O16 分钟前
Java List 集合介绍
windows
不瘦80斤不改名27 分钟前
HTML基础(一)
开发语言·前端·html
Shadow(⊙o⊙)28 分钟前
初识Qt+经典方式实现hello world!的交互
开发语言·c++·后端·qt·学习
Byte Wizard28 分钟前
C语言指针深入浅出3
c语言·开发语言
88号技师32 分钟前
2026年4月一区SCI-狒狒优化算法Baboon optimization algorithm-附Matlab免费代码
开发语言·算法·数学建模·matlab·优化算法
сокол1 小时前
【网安-Web渗透测试-内网渗透】内网横向移动——IPC连接
服务器·windows·网络安全·系统安全
平凡但不平庸的码农1 小时前
Go context 包详解
开发语言·后端·golang