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

相关推荐
m0_694845573 分钟前
tinylisp 是什么?超轻量 Lisp 解释器编译与运行教程
服务器·开发语言·云计算·github·lisp
春日见8 分钟前
如何创建一个PR
运维·开发语言·windows·git·docker·容器
C++ 老炮儿的技术栈11 分钟前
VS2015 + Qt 实现图形化Hello World(详细步骤)
c语言·开发语言·c++·windows·qt
派葛穆18 分钟前
Python-批量安装依赖
开发语言·python
MSTcheng.30 分钟前
【C++】C++11新特性(二)
java·开发语言·c++·c++11
晓131333 分钟前
第七章 【C语言篇:文件】 文件全面解析
linux·c语言·开发语言
愚者游世33 分钟前
Delegating Constructor(委托构造函数)各版本异同
开发语言·c++·程序人生·面试·改行学it
梵刹古音35 分钟前
【C语言】 指针基础与定义
c语言·开发语言·算法
Ekehlaft38 分钟前
这款国产 AI,让 Python 小白也能玩转编程
开发语言·人工智能·python·ai·aipy
rit843249941 分钟前
MATLAB中Teager能量算子提取与解调信号的实现
开发语言·matlab