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

相关推荐
AI街潜水的八角38 分钟前
Python电脑屏幕&摄像头录制软件(提供源代码)
开发语言·python
hadage23340 分钟前
--- git 的一些使用 ---
开发语言·git·python
lly2024063 小时前
HTML与CSS:构建网页的基石
开发语言
一只会写代码的猫3 小时前
面向高性能计算与网络服务的C++微内核架构设计与多线程优化实践探索与经验分享
java·开发语言·jvm
是小胡嘛4 小时前
C++之Any类的模拟实现
linux·开发语言·c++
csbysj20205 小时前
Vue.js 混入:深入理解与最佳实践
开发语言
百***86465 小时前
新版 WSL2 2.0 设置 Windows 和 WSL 镜像网络教程
windows
qq_479875436 小时前
X-Macros(1)
linux·服务器·windows
Gerardisite7 小时前
如何在微信个人号开发中有效管理API接口?
java·开发语言·python·微信·php
Want5957 小时前
C/C++跳动的爱心①
c语言·开发语言·c++