🦀

RustのBevyで--target=aarch64-pc-windows-msvcをやってみたかった。

2023/11/29に公開
PS C:\~~~\binary_test> cargo run --target=aarch64-pc-windows-msvc
   Compiling binary_test v0.0.0 (C:\~~~\binary_test)
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.

error: could not compile `binary_test` (bin "binary_test") due to previous error

仮説

MSVC v143 - VS 2022 C++は入っているんだけどな。Cython動く環境だし。
となると、Visual StudioのVS 2017 C++ビルドツールを入れればいいんでしょ?分かってる分かってる。


・・・どれだ、これ?

インストールする前に。

調べてみると、2017年版ではなく2022年版のを入れても問題なく動いた報告もある。
https://hirake.link/rust-で-link-exe-not-found-エラーが出た場合/
となればlink.exeが見つからない?もしくは・・・。

https://zenn.dev/atsushifx/articles/develop-lang-rust-install
この記事を見ると、C++コンパイラのPathを設定している。
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\binをシステム環境設定のPathに追加。
再起動。ダメでした。

解決

aarch64-pc-windows-msvcx86_64-pc-windows-msvcに変更するだけでよかった。
ドキュメントはちゃんと読もうね・・・。
https://doc.rust-lang.org/stable/rustc/platform-support.html#tier-2-with-host-tools

おまけ

rustupにMSVC版とGNU版があるようで、前者の場合VC++ Build toolsが必要になってくる。
https://hkou.hatenablog.com/entry/2016/12/04/115644
この環境では公式サイトで配布されているRUSTUP-INIT.EXE(64-BIT)を使用したため、確実にMSVC版ではある。

調べたサイト

https://qiita.com/mk-tool/items/0a602ce3d5eae428c308
https://hirake.link/rust-で-link-exe-not-found-エラーが出た場合/
https://zenn.dev/atsushifx/articles/develop-lang-rust-install
https://qiita.com/M_S/items/218d8b1fc3dd3737225e
https://hkou.hatenablog.com/entry/2016/12/04/115644
http://mpu.seesaa.net/article/455908337.html

Discussion