Window上学习使用rust语言碰到linker `link.exe` not found | = note: program not foundnote: the msvc targe

在Windows上学习Rust遇到link.exe找不到的错误,通常需要安装VisualStudio或BuildTools。但文章提供了不依赖VS的解决方案:使用rustup安装稳定版的x86_64-pc-windows-gnu工具链,然后设置为默认,使程序正常运行。
摘要由CSDN通过智能技术生成

按照rust的官方网站的指令开始学习rust,程序运行就会报错

linker `link.exe` not found | = note: program not foundnote: the msvc targe,具体报错如下:

cargo run
   Compiling hello-rust v0.1.0 (D:\gantStudyDemo\hello-rust)
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.

 

这个错误表明编译Rust程序时没有找到MSVC linker,需要通过安装Visual Studio 2017或更高版本或Visual Studio Build Tools解决该问题。这是因为Rust编译器通常使用Microsoft的C++编译器来编译Rust程序。

可以按照以下步骤来解决该问题:

  1. 访问Rust官方网站下载安装 Rust。
  2. 通过Rust官方指南中的步骤,检查您的安装是否成功。
  3. 如果您没有安装Visual Studio或Build Tools,则需要 下载并安装 Visual Studio 2017或更高版本 或 Build Tools for Visual Studio
  4. 确保在安装Visual Studio期间选择了Visual C++选项。
  5. 如果已安装Visual Studio或Build Tools,则尝试运行rustup default stable-x86_64-pc-windows-msvc,它会设置rustup工具链使用上面安装的MSVC工具链。

如果您已经按照上述步骤安装了Visual Studio或Build Tools,但仍然出现了相同的错误,请检查link.exe是否有没有与PATH环境变量中的位置。

注意!!!你会发现按照上面那样解决很麻烦,而且电脑配置没有那么好的情况下,去下载VS,你的电脑更加经不起折腾了。

查阅了很多资料,发现可以不依赖VS就能运行rust,使用如下指令即可

rustup toolchain install stable-x86_64-pc-windows-gnu

出现如下信息代表下载好了

 下载安装之后,运行下面指令

rustup default stable-x86_64-pc-windows-gnu

出现如下信息

OK,程序可以正常运行了

完美解决!

  • 11
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值