【问题标题】:`cargo build` fails with linking error "link.exe failed: exit code: 325595"`cargo build` 失败,链接错误“link.exe failed: exit code: 325595”
【发布时间】:2018-05-14 18:49:45
【问题描述】:

我有一个可以在 Linux、macOS 和 Windows 10 上正常编译的 Rust 项目。

我今天使用Visual Studio Installer 在我的 Windows 7 计算机上安装了以下单个组件:

  • VC++ 2015.3 v14.00 (v140) toolset for desktop
    • Windows Universal CRT SDK(依赖)
    • Windows 8.1 SDK(依赖)

之后,我使用来自official website 的新rustup-init.exe 安装了Rust。

当我在 Windows 7 计算机上的 Rust 项目上运行 cargo build 时,它失败并显示以下消息:

error: linking with `C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\link.exe\` failed: exit code: 325595.

在我的 Windows 10 计算机上单独运行 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\link.exe 不带任何参数会产生一些“帮助”信息,但在我的 Windows 7 计算机上,我会收到一个带有错误消息的窗口:

The application was unable to start correctly (0xc000007b).  Click Ok to close the application.

我的 Google-Fu 没有找到任何有用的信息。我试过了:

  • sfc /scannow
  • 确保 System32 没有 32 位 DLL
  • 确保 SysWOW64 没有 64 位 DLL

【问题讨论】:

标签: windows linker rust


【解决方案1】:

更改默认链接器可解决此问题。我的系统是 64 位的,但链接器指向的是 32 位的。

这个在锈book也有提到

 rustup default stable-x86_64-pc-windows-gnu

阅读this 了解更多关于为什么会发生这种情况的解释。

默认情况下,配置选择它为 32 位,因此运行上面给出的命令会将链接器切换为 64 位。

【讨论】:

  • 最好在你的答案中添加一些解释。
  • 当然!让我添加一些链接来解释为什么会发生这种情况!
  • 那是一种善意的解释!
【解决方案2】:

下载最新的 64 位运行时Visual C++ Redistributable for Visual Studio 2017 后,link.exe 可以在我的 Windows 7 计算机上运行。我现在可以编译我的 Rust 项目了。

我很惊讶 Visual Studio 安装程序不能确保为 2015 工具集安装必要的运行时组件。


更新:Stargateur 指出 Redistributable 可以直接从 Visual Studio 安装程序安装。 它是Visual C++ 2017 Redistributable Update 单个组件。

【讨论】:

  • visual studio 不是 C++ 的主要开发者,您需要检查一些选项。
  • @Stargateur 我不明白你的评论。
  • 安装 c++ redistributable visual studio 在安装程序中有一个选项
猜你喜欢
  • 1970-01-01
  • 2021-09-04
  • 2021-07-29
  • 2019-02-26
  • 1970-01-01
  • 2022-01-09
  • 2020-11-06
  • 1970-01-01
  • 2020-08-22
相关资源
最近更新 更多