windows10にRustをインストールしてHello Worldする

windows環境にrustをインストールして、hello worldを出力するまでの手順を記載。
環境
OS windows10 pro
Rustダウンロード
こちらのサイトからダウンロードします。
自分は64bit環境なので64-bitをダウンロードしました

Rustインストール
ダウンロードしたrustup-init.exeをダブルクリックして実行します。
コマンドプロンプトが起動するので、「Y」と入力してENTERキーを押下します。

今回は1を選択します。

インストールが完了したのでENTERキーを押下します。

次に指示通りに「%USERPROFILE%.cargo\bin」をPATHに通しておきます。

「Hello World」してみる
hello.rsという名前で、下記のコードで編集します。
fn main() {
println!("Hello World")
}
コンパイルします。
rustc hello.rs
下記のエラーが発生しました。
error: linker `link.exe` not found
|
= note: 指定されたファイルが見つかりません。 (os error 2)
note: the msvc targets depend on the msvc linker but `link.exe` was not found
note: please ensure that VS 2013, VS 2015, VS 2017 or VS 2019 was installed with the Visual C++ option
error: aborting due to previous error
こちらから「Build Tools for Visual Studio 2019」をダウンロードします

ダウンロードした「vs_buildtools__1842890002.1583385801.exe」を実行して、「C++ Build Tools」にチェックをしてインストールをします。

インストールが終ったら、再度コンパイルします。
rustc hello.rs
今度は問題なくコンパイルされたので、実行してみます。
.\hello.exe
<出力結果>
Hello World
-
前の記事
React エラー「Parsing error: Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>…>?」が発生した場合の対応法 2020.03.06
-
次の記事
Nuxt.js vue-barcodeを使用してバーコードをサイトに表示する 2020.03.06
コメントを書く