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

相关推荐
一只鹿鹿鹿3 分钟前
信息化项目管理规范(参考Word文件)
java·大数据·运维·开发语言·数据库
XGeFei7 分钟前
python中子线程与主线程的关系
开发语言·python
Chase_______11 分钟前
【Java杂项】final 关键字详解:变量、方法、类限制与引用可变性
java·开发语言·python
ruxingli20 分钟前
Golang iota详解
开发语言·后端·golang
我材不敲代码22 分钟前
Python venv 虚拟环境从入门到精通 + uv 高性能替代工具实战指南
开发语言·python·uv
l1t33 分钟前
DeepSeek总结的使用实体-组件-系统和基于存在性处理进行Python编程18-20
开发语言·python
磊 子39 分钟前
STL之deque和list以及两者与vector的对比
开发语言·c++·list
凤山老林41 分钟前
DDD(领域驱动设计)在复杂业务系统中的落地指南
java·开发语言·数据库·ddd·领域驱动
凯瑟琳.奥古斯特1 小时前
子查询原理与实战案例解析
开发语言·数据库·职场和发展·数据库开发
Eiceblue1 小时前
Python 操作 Excel:数据分组、分类汇总与取消分组全解
开发语言·python·excel