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

相关推荐
星栈独行16 分钟前
翻完 Pi 源码:它和 Codex、Claude Code 有何不同
开发语言·javascript·人工智能·程序人生
spencer_tseng36 分钟前
Redis + Nacos.bat
java·windows·dos
qq_4480111637 分钟前
C语言中的变量和函数的定义与声明
android·c语言·开发语言
会飞的小新2 小时前
Windows CMD 与 PowerShell 深度解析:底层原理、命令差异、自动化选型指南
运维·windows·自动化
孫治AllenSun2 小时前
【DataX】生产环境搭建DataX集群案例
java·开发语言·jvm
c238563 小时前
把 C++ 内存分配拆透:new 与 malloc 的三层血缘
开发语言·c++·算法
moonsims4 小时前
星闪在跨域无人化系统作用
开发语言·php
Iruoyaoxh4 小时前
栈和队列~
java·开发语言
Hrain-AI5 小时前
2026 企业 AI 编程智能体实战:Codex 与 Claude Code
开发语言·人工智能·kotlin
wdfk_prog5 小时前
嵌入式面试真题第 13 题:单硬件 Timer 下的高精度多路软件定时器架构设计
c语言·开发语言·面试·职场和发展·嵌入式