找回密码
 立即注册
首页 业界区 安全 rust学习第一课:window环境报错(error: linker `link. ...

rust学习第一课:window环境报错(error: linker `link.exe` not found)

石娅凉 2025-8-6 09:23:58
问题描述

当我们编写好第一个 hello world 程序,正想运行一下看看效果,but,报错了!
  1. error: linker `link.exe` not found
  2.   |
  3.   = note: program not found
复制代码
问题显而易见,我们没有这个链接器的可执行文件,根据官方文档安装visual studio code或者visual studio即可,但在这里我已经装了visual studio code,仍然报了错误,显然,我们要另寻解决方法。
解决方法

打开终端,我们输入一下命令
  1. rustup toolchain install stable-x86_64-pc-windows-gnu
复制代码
等待一段时间,可能要等好久...
运行完成后,我们继续运行下面的命令
  1. rustup default stable-x86_64-pc-windows-gnu
复制代码
再试一下运行你的 hello world 吧,它可以运行出来了!
这两条命令做了什么呢?

  • 第一条命令是安装稳定版本的 Rust GNU 工具链,在这里我们无法链接到msvc,查询得知 msvc 是Windows环境用来模拟Linux环境中提供gcc编译的,因为rust的编译依赖于gcc编译器,没错,就是C/C++的编译器。 msvc 的全称是 MinGW(Minimalist GNU for Windows)。
  • 第二条命令是设置默认的 Rust 工具链,设置之后运行rustc、cargo等命令就会默认使用刚刚安装的工具链。
其它问题


  • 下载缓慢,可自行搜索如何设置国内镜像


来源:豆瓜网用户自行投稿发布,如果侵权,请联系站长删除

相关推荐

您需要登录后才可以回帖 登录 | 立即注册