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

相关推荐
EnCi Zheng几秒前
P2G-Python字符串方法完全指南-split、join、strip、replace的Python编程利器
开发语言·python
爱学习的小囧2 分钟前
VCF 9 实验室网络部署全攻略:从硬件连接到配置实操
开发语言·网络·php
非凡ghost4 分钟前
AIMP(音乐播放软件)
前端·windows·音视频·firefox
xifangge20256 分钟前
【2026终极解法】彻底解决“由于找不到 msvcp140.dll,无法继续执行代码”报错(附微软运行库一键修复包)
windows·mysql·microsoft·报错·开发环境
liliangcsdn13 分钟前
LLM如何与mcp server交互示例
linux·开发语言·python
摇滚侠17 分钟前
Windows 查看占用端口的进程,并关闭进程
windows
军军君0119 分钟前
Three.js基础功能学习十五:智能黑板实现实例二
开发语言·前端·javascript·vue.js·3d·threejs·三维
汤姆yu21 分钟前
Windows系统下TRAE的安装与完整使用教程
windows·ai·trae·ai编程工具
维齐洛波奇特利(male)23 分钟前
@Pointcut(“execution(* com.hdzx..*(..))“)切入点与aop 导致无限循环
java·开发语言
来日可期131432 分钟前
C/C++ 反常识记录(1)—— 那些容易踩坑的语法细节
c语言·开发语言·c++