cargo buildしたら「error: linker `link.exe` not found」が出たとき

にあえん

October 1, 2023

そのまんまなタイトルですが、備忘録のために解決方法を記載しておきます。

Windows11でRustの開発中、cargo buildしたらこんな感じでエラーが出ました。

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.

wingetコマンドでビルドツールをインストールしてあげましょう。

winget install Microsoft.VisualStudio.2022.BuildTools

これが終わったら、Visual Studio Installerを起動します。

インストール済みのところに先ほどインストールしたビルドツールが表示されています。

ここの変更を押します。

「C++によるデスクトップ開発」を選択して、変更をクリックします。

これでインストールが開始されます!

インストールが完了したら再起動して、再度cargo buildを走らせれば、このエラーは消えます。

参考

Wingetを利用してWindows11にRust/Rustupを導入する

Rust で `link.exe` not found エラーが出た場合 | スイッチは男のロマン