Windowsでcargo build実行時にlinkerが見つからないエラーが発生した
linker `link.exe` not foundに対処した際のメモ
状況
Windowsで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.
対処法
エラーメッセージにある通り、Visual Studio 2017以降、またはVisual C++オプションをインストールしたBuild Tools for Visual Studioをインストールする必要がある。
次のコマンドでビルドツールをインストールする。
winget install Microsoft.VisualStudio.2022.BuildTools
Visual Studio Installerを起動して、「C++によるデスクトップ開発」を選択し変更を押す。 インストールの完了を待つ。