Rust「linker link.exe not found」の原因と直し方
linker link.exe not found は、C++ ビルドツールを入れるか GNU ツールチェーンに切り替えれば直る。
Windows 既定の MSVC ツールチェーンが Visual Studio のリンカーを要求するためである。
公開: 更新:
cargo build --target x86_64-pc-windows-msvc … error: linker `link.exe` not found | = note: No such file or directory (os error 2)
cargo build --target x86_64-pc-windows-gnu Compiling hello v0.1.0 (/tmp/hello) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
2026-10-19 に rust:1(Rust 1.99.1) で実際に打って取った出力。検証環境の詳細
要約
error: linker `link.exe` not found は、コンパイルではなくリンクの段階で出るエラーだ。
Windows 版の Rust は既定で x86_64-pc-windows-msvc ターゲットを使い、最後のリンクを Microsoft のリンカー(link.exe)に任せる。
rustup はこのリンカーを同梱しないため、Visual Studio 側のビルドツールが無い端末では必ずここで止まる。
Rust 自体の入れ直しでは直らない。
リンカーを用意するか、リンカーを必要としないツールチェーンに切り替えるかのどちらかである。
実行例
Linux の rust:1 コンテナで MSVC 向けにビルドすると、link.exe が見つからないというエラーで終了コード 101 になった。
リンカーに MinGW-w64 の gcc を指定した GNU 向けに切り替えると終了コード 0 で、Windows 用の hello.exe ができた(コンテナは Linux なので host 行は Linux のものになる)。
$ cargo build --target x86_64-pc-windows-msvc
Compiling hello v0.1.0 (/tmp/hello)
error: linker `link.exe` not found
|
= note: No such file or directory (os error 2)
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
error: could not compile `hello` (bin "hello") due to 1 previous error
$ echo $?
101$ rustc --version --verbose
rustc 1.99.1 (58cf8f9c3 2026-10-13)
binary: rustc
commit-hash: 58cf8f9c35b355199727627d07ae34a4e2846d67
commit-date: 2026-10-13
host: x86_64-unknown-linux-gnu
release: 1.99.1
LLVM version: 23.1.1$ rustc --print target-list | grep x86_64-pc-windows
x86_64-pc-windows-gnu
x86_64-pc-windows-gnullvm
x86_64-pc-windows-msvc$ cat .cargo/config.toml
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"$ cargo clean
Removed 29 files, 136.7KiB total$ cargo build --target x86_64-pc-windows-gnu
Compiling hello v0.1.0 (/tmp/hello)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
$ echo $?
0$ file target/x86_64-pc-windows-gnu/debug/hello.exe
target/x86_64-pc-windows-gnu/debug/hello.exe: PE32+ executable for MS Windows 5.02 (console), x86-64, 19 sections— 2026-10-19 時点の出力
検証環境Python 3.13.5 / Git 2.47.3 / Rust 1.99.1 / 2026-10-19 検証
- 検証日
- 実行環境
rust:1Debian GNU/Linux 13 (trixie)- バージョン
- Python 3.13.5
- Git 2.47.3
- Rust 1.99.1
この記事の「実行例」は、上記の環境で実際にコマンドを実行して得られた出力をそのまま掲載しています。 再現手順はリポジトリの検証スクリプトとして管理し、定期的に再実行して出力を更新しています。
解決策
1. C++ ビルドツールを入れる(推奨)
rustup の公式ドキュメントが案内している標準的な手順である。
Visual Studio Build Tools のインストーラーを起動し、ワークロードから C++ によるデスクトップ開発 を選ぶ。
個別コンポーネントとしては、MSVC のビルドツールと Windows SDK の 2 つが必要だ。
インストールが終わったらターミナルを開き直し、リンカーが見えるか確認する。
where.exe link.exe
cargo buildVisual Studio 本体を使っている場合は、同じワークロードが入っていれば追加のインストールは要らない。
2. GNU ツールチェーンへ切り替える
MSVC を入れられない環境では、GNU ツールチェーンに切り替える手もある。
この場合は MinGW-w64 の gcc がリンカーの役目を果たす。
rustup toolchain install stable-x86_64-pc-windows-gnu
rustup default stable-x86_64-pc-windows-gnu
cargo clean
cargo buildただし GNU ツールチェーンは、MSVC 向けにビルドされたクレートやシステムライブラリとの相性で別の問題が出ることがある。
配布物を Windows で動かすのが目的なら、MSVC 側を整えるほうが結局は近道だ。
3. いま使っているターゲットを確認する
どちらのツールチェーンで動いているのかは、次のコマンドの host 行で分かる。
rustc --version --verbosehost: x86_64-pc-windows-msvc と出ていれば MSVC、...-windows-gnu なら GNU だ。
切り替えたつもりで切り替わっていない、という取り違えはここで潰せる。
4. 切り替え後は cargo clean を挟む
ツールチェーンを変えると成果物の形式も変わる。target/ に前のターゲットの中間生成物が残っていると、リンク段階で不可解な失敗をすることがあるため、切り替え直後は cargo clean を一度実行しておくと余計な回り道をせずに済む。
よくある原因
- Visual Studio も Build Tools も入っていない。
新しい端末でrustupだけ入れたときの定番だ。 - Build Tools のインストーラーは実行したが、ワークロードを選ばずに閉じた。
インストーラーは既定で何も選ばないため、本体だけ入ってlink.exeは入らない。 - インストール直後の古いターミナルでそのまま
cargo buildした。PATHの変更は新しいプロセスにしか反映されない。 - ネット上の手順が GNU ツールチェーン前提だった。
MinGW-w64 を入れても、MSVC ターゲットのままではlink.exeを探し続ける。